views:

650

answers:

3

The whole question fits in the title. And to add some context: I'm not asking what is the best according to what the specs are saying, but rather what works the best given the mix of browsers deployed nowadays.

Some data points:

  • Google uses text/javascript for the JS used on their home page.
  • Google uses text/javascript on Google Docs.
  • Google uses application/x-javascript to serve JavaScript files with their Ajax libraries service.
  • Yahoo uses application/x-javascript to serve their JS.
  • Yahoo uses application/x-javascript for the JavaScript served on their home page.
+6  A: 

In most situations, the mime type the server sends makes no practical difference. I would go with application/javascript, which is also recommended by an RFC.

Matthew Flaschen
it's rfc 4329: http://www.ietf.org/rfc/rfc4329.txt
Christoph
+ 1 for link to RFC
Leonel
+4  A: 

It has been "text/javascript" but this is obsolete (see the IANA List) and now it should be "application/javascript" (see another IANA List).

Tim Büthe
+6  A: 
  • text/javascript - is obsolete
  • application/x-javascript - was experimental while deciding to move to ...
  • application/javascript is the current official MIME type for JS

That said, browsers ignore the content-type sent by the server and pay too much attention to the type attribute (and many don't yet recognise application/javascript).

My recommendation:

  • Use application/javascript on the server
  • Use text/javascript as a hack in type attributes in HTML documents
David Dorward
This question from a few months ago says the exact opposite. Someone is mistaken :)"Kelly's right, browsers tend to trust the MIME type sent with the response headers over the type attribute of the script tag"http://stackoverflow.com/questions/189850/what-is-the-javascript-mime-type-what-belongs-in-the-type-attribute-of-a-script/189877#189877
Marco