103

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

Obviously, one is supposed to be executed, and the other is supposed to be just 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?

ddavison
  • 27,048
  • 15
  • 78
  • 100

1 Answers1

102

Per this, text/javascript is obsolete. Use application/javascript instead.

text/javascript (Obsolete): JavaScript; Defined in and made obsolete in RFC 4329 in order to discourage its usage in favor of application/javascript. However, text/javascript is allowed in HTML 4 and 5 and, unlike application/javascript, has cross-browser support. The "type" attribute of the tag in HTML5 is optional and there is no need to use it at all since all browsers have always assumed the correct default (even in HTML 4 where it was required by the specification).

This standard is incompatible with IE<=8.

dthree
  • 18,488
  • 11
  • 69
  • 103
  • 1
    …but the same line says that while it may be obsolete, IE<8 doesn't understand `application/javascript`. – Bergi Jan 13 '14 at 18:49
  • 9
    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 Jan 13 '14 at 23:26
  • 7
    The [WG spec states that **`text/javascript` should be used.**](https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages) The linked wikipedia article does not contain that information anymore. – Fons Jun 15 '20 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](https://www.iana.org/assignments/media-types/media-types.xhtml). The entry for [text/javascript](https://www.iana.org/assignments/media-types/text/javascript) can be found in this list and references [RFC 4329](https://tools.ietf.org/html/rfc4329) which indeed declares **text/javascript** to be obsolete. – jmjohnson85 Dec 08 '20 at 16:57
  • 2
    According to IETF's [ECMAScript Media Types Updates](https://datatracker.ietf.org/doc/draft-ietf-dispatch-javascript-mjs/), RFC 4329 is obsolete. – Mike Apr 13 '21 at 17:49
  • Iana's list of official media types (https://www.iana.org/assignments/media-types/media-types.xhtml) still lists application/javascript and references RFC 4329. the IETF document you link, @Mike, is only a draft. – EricS Sep 25 '21 at 21:34