Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a good practice to ignore script type? [duplicate]

Tags:

html

Possible Duplicate:
HTML5 <script> declarations

I've heard a few people say that you don't need to specify a type="text/javascript" in a <script> tag, as this is the default type.

Is there any downside if I open my script tags as <script> instead of the more verbose <script type="text/javascript">?

like image 584
Christophe Avatar asked Jul 30 '12 21:07

Christophe


2 Answers

In HTML4 the type attribute is required:

http://www.w3.org/TR/html401/interact/scripts.html#h-18.2.1

In HTML5 it is not.

http://dev.w3.org/html5/markup/script.html

If you are going to use HTML4, then good practice certainly includes adhering to its specifications. If you're using HTML5, then it's pretty clear that <script> without a type is text/javascript, so you can safely omit it.

like image 121
kojiro Avatar answered Oct 17 '22 22:10

kojiro


Yes! You absolutely can omit the type. Make sure your document type is HTML5 if you care for validity.

<!doctype html>

It will work just as fine though with any browser you can think of.

It won't be considered "good practice" to break the specifications if you're not using HTML5 though :)

like image 45
Madara's Ghost Avatar answered Oct 17 '22 23:10

Madara's Ghost