Skip to main content
 首页 » 编程设计

javascript之<script type=text/javaScript> vs <script type=module>

2025年12月25日42lvdongjie

使用 <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.


(我强调)