When serving JavaScript files, is it better to use the application/javascript or application/x-javascript

  • 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 often ignore the content-type sent by the server and pay a lot of attention to the type attribute (and some may not yet recognise application/javascript).

My recommendation:

  • Use application/javascript on the server
  • Use HTML 5 and omit the type attribute from script elements

NB: the HTML specification contradicts the MIME standard, and there is an effort to change it back to text/javascript so this may change in future.


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.


Here's the 2020 answer to this question.

text/javascript is the correct JavaScript MIME type per the HTML Standard, which states:

Servers should use text/javascript for JavaScript resources. Servers should not use other JavaScript MIME types for JavaScript resources, and must not use non-JavaScript MIME types.

And also:

[…] the MIME type used to refer to JavaScript in this specification is text/javascript, since that is the most commonly used type, despite it being an officially obsoleted type according to RFC 4329.

Work is underway to reflect this reality in an RFC at the IETF level: https://datatracker.ietf.org/doc/draft-ietf-dispatch-javascript-mjs/

Any claim that "text/javascript is the obsolete one" is saying so based on RFC 4329, which both the HTML Standard and the abovementioned IETF draft (i.e. an upcoming RFC) are explicitly correcting.