I am delivering a JS response from a PHP file. When setting the Content-Type
header which value should I use, application/javascript
or text/javascript
?
What’s the difference between the two?
I am delivering a JS response from a PHP file. When setting the Content-Type
header which value should I use, application/javascript
or text/javascript
?
What’s the difference between the two?
According to the IANA Registered MIME media type list, JS has two registered MIME types; the obsolete text/javascript
and the now official application/javascript
.
Thus, use application/javascript
.
application/javascript
doesn’t work inside the type
attribute in script tags in IE 7 and older, but is fine for your HTTP Content-Type
header. I haven’t tested that though.
Apr 29, 2013 at 15:50
From Wikipedia on Internet Media Types
application/javascript:
JavaScript; Defined in RFC 4329 but not accepted in IE 8 or earlier
There is also the deprecated text/javascript
(which IE will probably not choke on).
According to IANA, on 2022-05-10, text/javascript
should be used.
Who knows what it'll be in a year!