Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

text/javascript vs application/javascript [duplicate]

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?

like image 623
ddavison Avatar asked Jan 13 '14 18:01

ddavison


People also ask

What is the difference between application javascript and text Javascript?

JavaScript is not human readable, so text/javascript was deprecated and application/javascript was introduced to replace it.

What should be the content-type for Javascript?

According to RFC 4329 the correct MIME type for JavaScript should be application/javascript . Howerver, older IE versions choke on this since they expect text/javascript .


1 Answers

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.

like image 79
dthree Avatar answered Sep 26 '22 10:09

dthree