Reputation: 9560
What is the difference between loading JavaScript files in HTML using <script type=text/javascript>
and <script type=module>
?
Upvotes: 33
Views: 17750
Reputation: 5026
The HTML5 specification discourages the use of type=text/javascript
:
From https://www.w3.org/TR/html5/semantics-scripting.html#element-attrdef-script-type:
Omitting the (type) attribute, or setting it to a JavaScript MIME type, means that the script is a classic script, to be interpreted according to the JavaScript Script top-level production. Classic scripts are affected by the charset, async, and defer attributes. Authors should omit the attribute, instead of redundantly giving a JavaScript MIME type.
Setting the attribute to an ASCII case-insensitive match for the string "module" means that the script is a module script, to be interpreted according to the JavaScript Module top-level production. Module scripts are not affected by the charset and defer attributes.
(emphasis by me)
Upvotes: 27