Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do HTML5 Script tag need type="javascript"? [duplicate]

Tags:

html

Possible Duplicate:
Do you need text/javascript specified in your <script> tags?

Do in HTML5, the <script> tag need attribute type="text/javascript"?
I mean isn't it obvious if the <script> tag will be contains javascript?

like image 356
GusDeCooL Avatar asked Jan 14 '13 17:01

GusDeCooL


People also ask

Do you need type attribute in script tag?

The type attribute is required in HTML4. 01 but optional in HTML5. The type shows what type to be parsed. NOTE: if the type attribute is a audio, HTML, video, or any MIME type besides JavaScript the code will NOT be executed.

Is type text/JavaScript necessary?

The type attribute in JavaScript is optional since the introduction of HTML5 brought some new improvements. JavaScript became the default language for HTML5 and modern browsers.

Are script tags required for JavaScript?

Dynamic script such as text/javascript . None, both the starting and ending tag are mandatory. Any element that accepts metadata content, or any element that accepts phrasing content.

What is the difference if any between script </ script and script type text/JavaScript </ script >?

text/javascript is the default type, so you can omit it, it makes no difference. Nothing, except in very special cases with old IE where if the first script element set the type to some other scripting language (e.g. VBScript) then that was the default if no type was specified.


1 Answers

No, it's now officially useless.

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

Simply do

<script src=yourpath.js></script> 

(yes, you can omit the quotes too)

Note that you don't have to worry about pre-HTML5 browsers, all of them always considered JavaScript to be the default script language.

like image 184
Denys Séguret Avatar answered Oct 14 '22 20:10

Denys Séguret