Is it really necessary to put "text/javascript" in the <script> tag?

Asked

Viewed 843 times

31

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

But even so, still in updated Ides (such as Sublime Text 3), the autocomplete mechanism causes the tag <script> is declared with type="text/javascript".

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

Some Ides still ask for compatibility?

2 answers

43


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

This attribute specifies the scripting language of the element’s 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 must fill 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 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".

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

  • The second link is broken

  • 1

    Updated link! :)

11

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

  • application/javascript or
  • application/ecmascript

These were necessary for older browsers of the time (e.g., IE8). In even older browsers, the attribute was used language="javascript", which has been totally discontinued.

If you use HTML5, it makes no sense to use the type, since pre-modern browsers are not compatible with this HTML specification.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.