Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <script> tag with type and <script> without type? [duplicate]

Possible Duplicate:
Should I include type=“text/javascript” in my SCRIPT tags?

I was writing HTML and found that even if the type in the script tag is not set to javascript, the javascript code in the tag can still be evaluated.

so I was just wondering what the difference is between the script tag with type and one without?

like image 638
dailinge Avatar asked Mar 11 '12 21:03

dailinge


1 Answers

In HTML 4, the type attribute is required. In my experience, all browsers will default to text/javascript if it is absent, but that behaviour is not defined anywhere. While you can in theory leave it out and assume it will be interpreted as JavaScript, it's invalid HTML, so why not add it.

In HTML 5, the type attribute is optional and defaults to text/javascript:

The type attribute gives the language of the script or format of the data. If the attribute is present, its value must be a valid MIME type. The charset parameter must not be specified. The default, which is used if the attribute is absent, is "text/javascript".

like image 75
Pekka Avatar answered Oct 26 '22 22:10

Pekka