124

I am curious about the semantics of the MIME types application/javascript versus text/javascript.

Apart from the obvious - one is intended to be executed, and the other is text.

I see application/javascript when looking at headers of an external .js load.

HTTP/1.1 200 OK
Date: Mon, 13 Jan 2014 18:32:58 GMT
Server: Apache/2.2.22 (Unix) mod_ssl/2.2.22 OpenSSL/0.9.8e-fips-rhel5
Content-Type: application/javascript
Content-Length: 856
keep-alive: timeout=5, max=59
Via: 1.1 (jetty)
Accept-Ranges: bytes

If this application/javascript will execute the javascript, why don't we use

<script type="application/javascript">
  // some js code.
</script>

And vice-versa, why is an external js load not text/javascript?

0

1 Answer 1

137

Per IETF RFC 9239 text/javascript is now standard and application/javascript is now considered obsolete.

The media type registrations herein are divided into two major categories: (1) the sole media type "text/javascript", which is now in common usage and (2) all of the media types that are obsolete (i.e., "application/ecmascript", "application/javascript", "application/x-ecmascript", "application/ x-javascript", "text/ecmascript", "text/javascript1.0", "text/javascript1.1", "text/javascript1.2", "text/ javascript1.3", "text/javascript1.4", "text/javascript1.5", "text/jscript", "text/livescript", and "text/xecmascript").

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

7
  • 1
    …but the same line says that while it may be obsolete, IE<8 doesn't understand application/javascript.
    – Bergi
    Commented Jan 13, 2014 at 18:49
  • 10
    Sry, I meant IE<=8 whom still many people (not me) want to support. I only meant that you should mention in your answer that there are incompatible legacy engines.
    – Bergi
    Commented Jan 13, 2014 at 23:26
  • 9
    The WG spec states that text/javascript should be used. The linked wikipedia article does not contain that information anymore.
    – Fons
    Commented Jun 15, 2020 at 18:45
  • 1
    The Wikipedia article linked in this answer no longer contains the "List of common media types" but instead links to the IANA list of official media types. The entry for text/javascript can be found in this list and references RFC 4329 which indeed declares text/javascript to be obsolete. Commented Dec 8, 2020 at 16:57
  • 5
    According to IETF's ECMAScript Media Types Updates, RFC 4329 is obsolete.
    – Mike
    Commented Apr 13, 2021 at 17:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.