<link type="text/css" media="all" rel="stylesheet" href="./foo.css.txt" />
Firbug Error
The stylesheet foo.css.txt was not loaded because its MIME type, “text/plain”, is not “text/css”.
Explanation
The browser is interpreting the CSS as a text document rather than a CSS, despite any effort to force it’s MIME through the browser. Naturally, in production I will be using foo.css (w/o the txt extension), but I would think this would be possible. It works for JavaScript:
<script type="text/javascript" src="./index.js.txt"></script>
Other Thoughts
-
Setting
type="css"doesn’t show an error in Firebug and the page validates, but the CSS doesn’t load properly – I’m pretty sure that’s not a valid MIME type though. I tried to find a list of MIME types off W3C, but as with everything it’s difficult to find/understand W3C -
This does work with other, less popular, extensions such as dat:
href="./foo.css.dat"
When you use the
typeattribute in HTML you are saying “When you fetch this resource, expect to get this type of data.” This allows user agents (such as browsers) to avoid requesting resources that they know they can’t handle. For CSS you need to set this totext/css.When the server responds to the request, the HTTP
Content-Typeheader says “This content is of this type”. It is canonical and must also be set totext/cssfor CSS data.Because you have used a .txt file, the server (in a default configuration) says that the file contains data that is
text/plainso it tells the browser that. You cannot override this from the browser.Browsers, for various reasons, tend to ignore the Content-Type specified by servers for JavaScript. This could be considered a bug in those browsers.
cssis not a registered MIME type, the browser doesn’t recognise it as a stylesheet language that it can understand, so it doesn’t event try to download it.The W3C isn’t responsible for the MIME type registry, which you can find at http://www.iana.org/assignments/media-types/