Robbert Broersma and I used to mail about this in the past. It isn't very interesting, but quite important.
text/html
text/plain
instead, but that would have given some trouble in other, more compliant browsers. (Not that Internet Explorer is the only evil browser.)text/css
application/xml
text/xml
(you can check that quite easily with ctrl+i on Mozilla, Windows), switch today. text/xml
is in process of being deprecated and already has serious encoding problems.application/xhtml+xml
application/x-javascript
text/javascript
instead, although it is unofficial, it is the best supported of the two (read: the only one Internet Explorer supports). application/x-javascript
is the only one that is semi-official though (the x-prefix is used, since it hasn't been registered yet).I consider these three MIME types as the most important, but probably not most used, on the internet. Other XML MIME types include application/rdf+xml
for RDF documents (think of RSS 1.0), the not yet official application/atom+xml
which is used for Atom (not an abbreviation) documents. For other RSS feeds I use application/rss+xml
, which is also not official yet and probably never will be since RSS doesn't have the intention to become a standard.
There is also an XML DTD MIME type: application/xml-dtd
. Note that this one uses a hyphen, since a DTD doesn't use XML syntax. Furthermore there is text/plain
and if you mix MIME types (using content negotiation or similar) you will probably get into trouble because of RFC 3023 - XML Media Types, which Mark Pilgrim explains as well in XML on the Web Has Failed. I'm not going to explain it here, but I can tell you, you have to know about it the other day. Using UTF-8 can save you a lot of trouble though.
Mapping MIME types to files is easy. As is mapping the character encoding (for application/xml
the character encoding is utf-8 by default.):
AddType {insert mime here};charset=utf-8 .{extension here}
Examples:
AddType application/atom+xml .atom
AddType text/html;charset=utf-8 .html
(Note that Apache might have enabled some of those by default.)
If I'm not mistaken, Mozilla stops loading stylesheets (and scripts, for that matter) if the applied TYPE
attribute doesn't match the Content-Type
value of the HTTP response. Only when it is in X(HT)ML rendering mode, though.
So, if you have a LINK
to a CSS file with TYPE
equal to text/css
, but the CSS file is served with Content-Type: text/plain
, Mozilla won't load it.
Asbjørn luckily filled the gap and at least mentioned text/css
(mind, not that one would youse this type that often... ;-) )
Asbjørn, only in standard compliant mode. But I'm not sure if they are checking the TYPE
attribute or just the file referred to, since after all, the TYPE
attribute is just a hint and probably wrong. For example, I know Mozilla supports type="text/xslt"
(and text/xsl
) on the XML Style Sheet PI for compatibility with Internet Explorer. If you actually serve the XSLT file with that MIME type it won't be loaded.
I added text/css
by the way.
Note that you can mix mime types on a page. Eg: when using ‹style type="text/css"› on a page of "text/html". Hmmm.
Via Weblog about Markup & Style:
An excellent example of why a browser shouldn’t second-guess file types.
I have an XML file that calls an XSLT file in as a stylesheet. It works fine in IE, and also in Mozilla Firefox 0.9.2 on the local machine, but when I upload it to a server, IE still works fine, but Mozilla gives an error:
Error loading stylesheet: An XSLT stylesheet does not have an XML mimetype:
The XML file has this:
<?xml-stylesheet type="text/xsl" href="cssformat.xsl"?>
and the stylesheet has this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
On Tools -> Page Info, the type says text/html in the local version that's okay in Mozilla, but type is unknown in the error version on the server.
Does anyone know why?
Oh, how weird, I uploaded it to another server and it worked although the type still says "text/html". Maybe something with the Apache or whatever server configuration is different.
Is there a way to set the MIME type from the .xml or .xslt file? In a meta tag or something?
O please, no META
elements for XML.
Use a .xml extension for your XSLT file and it will probably work.