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.
It used to be
language="javacript"
. Then it changed totype="text/javascript"
. Now it istype="application/javacript"
. Ok this is getting dumb. Some of the older browsers don't recognize the newapplication/javascript
, but still recognize the oldertext/javascript
. I plan to continue using this, or else I'll waste hours of my time trying to change EVERY instance oftext/javascript
intoapplication/javascript
.Now some day the opposite might be true. Some day the newest browsers might reject the old technique in order to be strictly standard's compliant.
But until people viewing my website start complaining that "ever since upgrading my browser, about 50% of your website disappeared", I have no motive to change the code in my website.
If you choose to use application/javascript for js in your pages, IE7 and IE8 will not run your script! Blame Microsoft all you want, but if you want most people to run your pages use text/javascript.
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.
It has been "text/javascript" but this is obsolete (see the IANA List) and now it should be "application/javascript" (see another IANA List).
text/javascript
is obsoleteapplication/x-javascript
was experimental while deciding to move to…application/javascript
is the current official MIME type for JSThat said, browsers often ignore the
content-type
sent by the server and pay a lot of attention to thetype
attribute (and some may not yet recogniseapplication/javascript
).My recommendation:
type
attribute from script elements