The year is almost 2020 as of this writing, and the HTML5 specification officially became a stable W3C Recommendation in 2014. Is it now time to stop using the beloved type attribute in your script tags? That's the magical question that we will tackle here today. And the answer isn't as simple as you might think. So do keep up as I navigate through various technologies, rules and committees on the search for this answer.
The HTML5 specification urges developers to omit the attribute as it is redundant in nature when used with the script tag. But most websites still have it in place (mainly because most large websites are pretty old). The official word from the W3C is stated as follows:
Not exactly pushing you to remove it. But essentially, it's saying you can remove it.
Why it's difficult to remove
As mentioned above, most websites on the web are relatively old. The numbers are hard to come by, but from the looks of it "most" websites are not HTML5 certified. They were around before these new standards came into existence, and so they aren't wrong by including older elements in the sense that they came first. Older websites also tend to have many many more web pages, such as thousands. And paying a developer to go in and remove the 'type' attribute on every page seems like poor resource management
I myself have 'type' on almost every single page of this blog. Why is that? Because this blog is older than you think. And back in the day, we used the type attribute and we liked it. And believe me as much as I want to follow the newest guidelines and specifications, the muscle memory is real and I just like having the explicit type set. What if one day it changes and it's required again? I will be covered.
But going back to the older website discussion. The type attribute is required in HTML 4.01, the predecessor to HTML5. There is not default type set if you omit, causing unexpected issues I'm sure depending on the browser. The official specification states the following.
When should you use it?
All the others 'might' work on 'some' browsers. But why take the risk. So once again we ask, when should we use it? There's one other value that the type attribute can take on, and that is module.
What's a module?
And you can then use the import keyword later on to import that module from another module. Current technologies such as Node.js have made use of modules since their inception. So they aren't anything new.
Working on older websites
Large organizations, such as Google and Microsoft, can for sure work at staying up to date on the latest specifications and standards. But most websites on the web are not Google or Microsoft.
Even the W3's very own website doesn't quite match up just ye and is running on 4.01.
So if you are working on their website, then do continue to include the type attribute please. But if you working on a brand new HTML5 project and want to follow the latest standards, feel safe in knowing that the browser default has got you covered.
I hope you enjoyed this deeper look at scripts, specifications and standards as I attempt to unravel the mysteries of the web development world. Comment down below if you are like me and prefer to include the type tag, or if you are keeping up to date with the standards.