Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is difference between text/javascript and application/javascript [duplicate]

Tags:

javascript

Possible Duplicate:
When serving JavaScript files, is it better to use the application/javascript or application/x-javascript

what is difference between text/javascript and application/javascript?

As IE will completely ignore the script tag if you have set type attribute to application/javascript.

But what is the main difference and in which case we need to use the particular.

like image 227
Avinash Avatar asked May 25 '11 10:05

Avinash


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 is text javascript?

HTML | <script> type Attribute The HTML <script> type Attribute is used to specify the MIME type of script and identify the content of the Tag. It has a Default value which is “text/javascript”.

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

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).

like image 96
Quentin Avatar answered Oct 07 '22 01:10

Quentin