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.
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.
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>
Only if you need backwards compatibility. For HTML5 and javascript code (not other types of script) it is unnecessary.
As for omitting type, yes, it will still work, but in XHTML 1.0 and HTML 4.01 is considered invalid.
[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.