What is the javascript MIME type for the type attribute of a script tag?
JavascriptMime TypesJavascript Problem Overview
What is the MIME type of javascript?
More specifically, what is the right thing to put in the "type" attribute of a script tag? application/x-javascript
and text/javascript
seem to be the main contenders.
Javascript Solutions
Solution 1 - Javascript
This is a common mistake. The MIME type for javascript wasn't standardized for years. It's now officially: "application/javascript".
The real kicker here is that most browsers won't use that attribute anyway, at least not in the case of the script tag. They actually peek inside the packet and determine the type for themselves.
So the bottom line is that the type="text/javascript" doesn't do anything as far as the javascript is concerned, but it's part of the spec for both HTML 4 and XHTML 1.0.
Solution 2 - Javascript
Far out this is the first page I've found on the topic with any sense about it.
My collective research suggests:
text/javascript
as Keparo stated must be used in html4 and xhtml1 if you want it to validate. Though browsers ignore it.application/javascript
is expected to be the new official MIME type if everyone agrees and when everything catches up.application/x-javascript
(x meaning unofficial) is the current server side MIME reference for javascript.- Everyone expects that as per usual, Microsoft will decide to do something completely different to further confuse and stuff up the matter.
Summary: For now, if you want your html/xhtml to work in MSIE and validate with W3C then declare type="text/javascript"
. If you want your web server to know that you mean javascript then use application/x-javascript
.
Solution 3 - Javascript
text/javascript
I believe IE doesn't accept application/x-javascript
Solution 4 - Javascript
In a script tag I would use text/javascript. This appears in the HTML 4.0 specification, anyway.
http://www.w3.org/TR/REC-html40/interact/scripts.html
[EDIT] Funny how the RFC that standardized on application/javascript is 2 years old, but text/javascript is still more common. Is this yet another case of custom triumphing over standards? It also appears in HTML5.
Solution 5 - Javascript
The official RFC that defines the Javascript MIME Type is RFC4329.
7. JavaScript Media Types
7.1. text/javascript (obsolete)
Type name: text
Subtype name: javascript
Required parameters: none
Optional parameters: charset, see section 4.1.
Encoding considerations:
The same as the considerations in section 3.1 of [RFC3023].
Security considerations: See section 5.
Interoperability considerations:
None, except as noted in other sections of this document.
Published specification: [JS15]
Applications which use this media type:
Script interpreters as discussed in this document.
Additional information:
Magic number(s): n/a
File extension(s): .js
Macintosh File Type Code(s): TEXT
Person & email address to contact for further information:
See Author's Address section.
Intended usage: OBSOLETE
Restrictions on usage: n/a
Author: See Author's Address section.
Change controller: The IESG.
7.2. application/javascript
Type name: application
Subtype name: javascript
Required parameters: none
Optional parameters: charset, see section 4.1.
Encoding considerations:
The same as the considerations in section 3.2 of [RFC3023].
Security considerations: See section 5.
Interoperability considerations:
None, except as noted in other sections of this document.
Published specification: [JS15]
Applications which use this media type:
Script interpreters as discussed in this document.
Additional information:
Magic number(s): n/a
File extension(s): .js
Macintosh File Type Code(s): TEXT
Person & email address to contact for further information:
See Author's Address section.
Intended usage: COMMON
Restrictions on usage: n/a
Author: See Author's Address section.
Change controller: The IESG.