Playr Blog

Your resource for all things playr. New game announcements, updates, bug fixes, news, you can find it first here.


Sunday, October 26, 2008

Curious bug with S3

During the process of rebranding the playr sites I found a curious bug in the way Firefox handles CSS files.  I wanted to reduce the load on my server so I've hosted some of the files on the Amazon S3 Simple Storage Service.  Great service, practically unlimited bandwidth and very cheap to boot.

However, for reasons unknown, when I uploaded my CSS to S3 it was saved with a content type of binary/octet-stream.  As any g33k will know that's an encoding used to tranfer generic files, not a specific content type like text/css, or audio/mp3.  Whilst this doesn't faze IE or Safari it did cause a problem for Firefox.  The CSS file was supposed to @import some other CSS from other files but when Firefox saw the CSS, and the fact that it was in a binary encoding it refused to parse it as CSS.  This resulted in no CSS loading and the entire page looking broken.

Moving the CSS to a standard Apache host solved the problem but I wanted it hosted on S3.  I asked the question in the S3 support forum and got a reply which pointed me at Bucket Explorer.  I used this to manually set the content type to text/css and the problem is solved in Firefox now.

Was this a bug in the way Firefox handles CSS files with the wrong content-type coming from the server or was it a bug in the way my S3 client failed to identify the file as CSS and set the content-type accordingly?  We may not know but I'll be submitting some bug reports for sure.

UPDATE: I have submitted a bug report to bugzilla and I have contacted Interarchy support as well, fingers crossed somebody will resolve the issue.  In the mean time I have found that Transmit does correctly set the content-type of CSS files it uploads to S3.

3 comments:

Griffer said...

Your bugzilla bug has been reported as a duplicate of:
https://bugzilla.mozilla.org/show_bug.cgi?id=156145
Which was reported in 2002.

It's status is 'verified invalid'.

Gaby said...

Ah yes, I saw that. They have rolled it into a different bug too. One poster suggests that it's not a bug, it's the proper behaviour.

In order for the pages to render consistently across browsers I used a DOCTYPE of HTML4.01 Strict. It's entirely possible that strict adherence to that schema means that CSS files must be served with a content type of text/css. If firefox was keeping to the standard, and it probably was, then it was correct to not render the CSS. I haven't tried this but if I went with a more lax DOCTYPE it might render fine. Curious.

Hey ho, at least it's something they're aware of.

Zack Weinberg said...

Yes, Firefox is correct to ignore CSS files served with a MIME type other than text/css. The theory is that the content of the file is not to be trusted; it may look like CSS but if the MIME type says it's something else then it's something else (perhaps some other, subtly different style-rule format that the browser doesn't understand.)

I personally think this is precisely backward, but it'd break more stuff than it would fix to change it now. (Also, there are maniacs, and I use the term advisedly, who will defend the current rule to the death.)