MIME types enable browsers to recognize the filetype of a file which has been sent via HTTP by the webserver. As a result the browser is able to choose a suitable displaying method. Common MIME types are for example text/html for html-files or image/jpeg for jpeg-files.
A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.
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.
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.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
.
text/javascript
I believe IE doesn't accept application/x-javascript
Specifying the scripting language
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With