0

Would there be any functionality/serving problems on an Apache2 by changing the following default MIME types...

.js  : application/x-javascript
.xml : application/xml

To this...

.js  : text/javascript
.xml : text/xml

My testing seems to show it will work, but I don't fully understand the purpose of MIME types as they relate to serving files.

Jeff
  • 1,416
  • 3
  • 28
  • 50

2 Answers2

2

text/xml can be a problem. Some caching proxies will rewrite the character encoding of text/* files. In the case of an XML file, this could make the actual character encoding differ from the character encoding declared within the document itself. And besides, I think text/xml has been deprecated.

http://hsivonen.iki.fi/producing-xml/#textxml

So always use application/xml for generic XML documents, and application/*+xml for specific documents which have their own registered MIME types (application/xul+xml for XUL, for example).

The only correct media type for javascript is application/javascript (or application/ecmascript, which is more strictly defined).

http://www.rfc-editor.org/rfc/rfc4329.txt

That said, many browsers won't care if you serve javascript as text/plain or even make something up altogether.

TRiG
  • 1,181
  • 3
  • 13
  • 30
2

You need to be careful with mime types as they're sent to the browser to help them interpret what way to render certain files.

Changing these two particular MIME types shouldn't hurt, but I'd be very wary of doing this in general. The mime type is sent with the headers for that particular file and changing those may result in unexpected behaviour with certain clients.

i.e. you can't really tell what will happen by changing mime types as such, as that's client specific. You'd need someone with experience of all the various web browsers to tell you in this case, or you'd need to go test it yourself. In general, that's what you'd need to be careful of.

Philip Reynolds
  • 9,799
  • 1
  • 34
  • 33
  • Thanks Phil. I began investigating this because of the way Google hosts their jQuery.js file. If you look at their headers, they use `text/javascript` instead of `application/x-javascript`. I assumed, based on that information, that it would probably be okay. – Jeff Dec 09 '09 at 13:19
  • Oops. Here is the link to Googles' jQuery: http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js . Check the headers. – Jeff Dec 09 '09 at 13:20