<script>: type attribute
<script> 元素的 type 属性指示该元素表示的脚本类型:经典脚本、导入映射、JavaScript 模块、推测规则或数据块。
¥The type attribute of the <script> element indicates the type of script represented by the element: a classic script, an import map, a JavaScript module, speculation rules, or a data block.
值
¥Value
该属性的值指示脚本表示的数据类型,并且将是以下之一:
¥The value of this attribute indicates the type of data represented by the script, and will be one of the following:
- 属性未设置(默认)、空字符串或 JavaScript MIME 类型
- 
    指示该脚本是 "经典脚本",包含 JavaScript 代码。如果脚本引用 JavaScript 代码而不是指定 MIME 类型,则鼓励作者省略该属性。JavaScript MIME 类型是 IANA 媒体类型规范中列出。 
- importmap
- 
    该值指示元素的主体包含导入映射。导入映射是一个 JSON 对象,开发者可以使用它来控制浏览器在导入 JavaScript 模块 时如何解析模块说明符。 
- module
- 
    该值导致代码被视为 JavaScript 模块。脚本内容的处理被推迟。 charset和defer属性无效。有关使用module的信息,请参阅我们的 JavaScript 模块 指南。与经典脚本不同,模块脚本需要使用 CORS 协议进行跨源获取。
- speculationrulesExperimental
- 
    该值表明元素的主体包含推测规则。推测规则采用 JSON 对象的形式,确定浏览器应预取或预渲染哪些资源。这是 Speculation Rules API 的一部分。 
- 任何其他值
- 
    嵌入的内容被视为数据块,并且不会被浏览器处理。开发者必须使用非 JavaScript MIME 类型的有效 MIME 类型来表示数据块。所有其他属性都将被忽略,包括 src属性。
注意:在早期的浏览器中,类型标识嵌入或导入(通过
src属性)代码的脚本语言。¥Note: In earlier browsers, the type identified the scripting language of the embedded or imported (via the
srcattribute) code.
规范
| Specification | 
|---|
| HTML Standard # attr-script-type | 
浏览器兼容性
BCD tables only load in the browser
¥Browser compatibility