what is difference between text/javascript and application/javascript

text/javascript was introduced when the web was young and people hadn't thought things through.

Then people thought things through, and decided that text/* should be reserved for things designed to be human readable (which is why some XML is text/xml and other XML is application/xml). JavaScript is not human readable, so text/javascript was deprecated and application/javascript was introduced to replace it.

Years later, some browsers still haven't caught up.

You can configure your server to always serve application/javascript in the HTTP headers; browsers that don't support it also pay no attention to the actual content-type.

For the time being, if you are writing HTML 4 or XHTML 1, specify text/javascript in the type attribute for the sake of backwards compatibility. If you are writing HTML 5, then omit the type attribute (as it is now optional).


HTML 4.01 (1999) specification suggests using MIME type text/javascript (http://www.w3.org/TR/1999/REC-html401-19991224/interact/scripts.html#h-18.2.2.2).

However, RFC 4329 (2006) now recommends the use of application/javascript.

It seems that historically text/javascript was used a lot and since it was the type that browsers most likely supported, this was the type that got suggested also in the HTML specification. Ideally, you would use application/javascript.

In practice you may need to use text/javascript to provide compatibility with less-conforming browsers.

Tags:

Javascript