使用 <script type=text/javascript>
在 HTML 中加载 JavaScript 文件有什么区别?和 <script type=module>
?
最佳答案
HTML5 规范不鼓励使用 type=text/javascript
:
来自 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.
(我强调)
关于javascript - <script type=text/javaScript> vs <script type=module>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51418964/