Do I really need to put "text / javascript" in the script tag?

31

We are in 2016. I have read in some places on the internet that it is no longer necessary to use this type="text/javascript" statement. In fact, using the script tag without declaring this snippet does not affect Javascript's workings at all.

However, even in updated IDEs (such as Sublime Text 3), the autocompletion engine causes the <script> tag to be declared with type="text/javascript" .

I wonder if it's safe to stop using text/javascript .

Are some IDEs still a matter of compatibility?

    
asked by anonymous 29.11.2016 / 11:42

2 answers

44

In the HTML 4.x version, the type attribute is required ( W3 ).

  

This attribute specifies the scripting language of the element   contents and overrides the default scripting language. The scripting   language is specified as a content type (e.g., "text / javascript").    Authors must supply a value for this attribute. There is no default   value for this attribute.

Griffin: "Creators should fill in the value of this attribute, there is no default value for it."

In HTML 5, the attribute is optional , if you do not set the default will be text/javascript ( W3 )

  

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

Griffin: The default value if the attribute is missing is: "text / javascript".

    
29.11.2016 / 11:47
12

Complementing, the type="text/javascript" attribute (HTML 4 standard) became obsolete in April 2006 (for more than 10 years of this question) according to RFC 4329 , being replaced from then on by

  • application/javascript or
  • application/ecmascript

That were needed for older browsers of the time (eg, IE8). In older browsers, the language="javascript" attribute was used, which was completely discontinued.

If you use HTML5, it does not make sense to use type , since premodern browsers are not compatible with this HTML specification.

    
20.01.2018 / 02:07