0

I have noticed in our local code base there are some SCRIPT tags without the TYPE attribute in them.

It doesn't seem to be causing any issues, is it not a requirement? I am concerned it may cause issues down the line.

shenku
  • 11,969
  • 12
  • 64
  • 118

2 Answers2

2

It is not a requirement as of HTML5. If type is left off, it is assumed to be JavaScript. You only need the type for other kinds of scripts. Non-JS based script tags are becoming more common. People often use them to store their client side templates.

For example in Angular, it's common to see script tags like <script type="text/ng-template" id="mytemplate.html">...</script>

Matt Greer
  • 60,826
  • 17
  • 123
  • 123
1

Only if you need backwards compatibility. For HTML5 and javascript code (not other types of script) it is unnecessary.

Similar question on SO

As for omitting type, yes, it will still work, but in XHTML 1.0 and HTML 4.01 is considered invalid.

From Mozilla Developer site

[type] if this attribute is absent, the script is treated as JavaScript.

From Douglas Crockford's website

This attribute is optional. Since Netscape 2, the default programming language in all browsers has been JavaScript. In XHTML, this attribute is required and unnecessary. In HTML, it is better to leave it out. The browser knows what to do.

Community
  • 1
  • 1
seangwright
  • 17,245
  • 6
  • 42
  • 54