summaryrefslogtreecommitdiff
path: root/devdocs/html/element%2Fscript%2Ftype.html
blob: 45f928a60153a74c43fc8be85f8045485221b8c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<header><h1>&lt;script&gt;: type attribute</h1></header><div class="section-content"><p>The <code>type</code> attribute of the <a href="../script"><code>&lt;script&gt;</code></a> element indicates the <em>type</em> of script represented by the element: a classic script, an import map, a JavaScript module, speculation rules, or a data block.</p></div>
<h2 id="value">Value</h2>
<div class="section-content">
<p>The value of this attribute indicates the type of data represented by the script, and will be one of the following:</p> <dl> <dt id="attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type"><a href="#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type"><strong>Attribute is not set (default), an empty string, or a JavaScript MIME type</strong></a></dt> <dd> <p> Indicates that the script is a "classic script", containing JavaScript code. Authors are encouraged to omit the attribute if the script refers to JavaScript code rather than specify a MIME type. JavaScript MIME types are <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#textjavascript">listed in the IANA media types specification</a>. </p> </dd> <dt id="sect1"><a href="type/importmap"><code>importmap</code></a></dt> <dd> <p> This value indicates that the body of the element contains an import map. The import map is a JSON object that developers can use to control how the browser resolves module specifiers when importing <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#importing_modules_using_import_maps">JavaScript modules</a>. </p> </dd> <dt id="module"><a href="#module"><code>module</code></a></dt> <dd> <p> This value causes the code to be treated as a JavaScript module. The processing of the script contents is deferred. The <code>charset</code> and <code>defer</code> attributes have no effect. For information on using <code>module</code>, see our <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">JavaScript modules</a> guide. Unlike classic scripts, module scripts require the use of the CORS protocol for cross-origin fetching. </p> </dd> <dt id="sect2">
<a href="type/speculationrules"><code>speculationrules</code></a> <abbr class="icon icon-experimental" title="Experimental. Expect behavior to change in the future."> <span class="visually-hidden">Experimental</span> </abbr>
</dt> <dd> <p> This value indicates that the body of the element contains speculation rules. Speculation rules take the form of a JSON object that determine what resources should be prefetched or prerendered by the browser. This is part of the <a href="https://developer.mozilla.org/en-US/docs/Web/Performance/Speculative_loading#the_speculation_rules_api">speculation rules API</a>. </p> </dd> <dt id="any_other_value"><a href="#any_other_value"><strong>Any other value</strong></a></dt> <dd> <p> The embedded content is treated as a data block, and won't be processed by the browser. Developers must use a valid MIME type that is not a JavaScript MIME type to denote data blocks. All of the other attributes will be ignored, including the <code>src</code> attribute. </p> </dd> </dl> <div class="notecard note" id="sect3"> <p><strong>Note:</strong> In earlier browsers, the type identified the scripting language of the embedded or imported (via the <code>src</code> attribute) code.</p> </div>
</div>
<h2 id="specifications">Specifications</h2>
<div class="notecard warning">
<strong>No specification found</strong><p>No specification data found for <code>html.elements.script.type</code>.<br><a href="#on-github">Check for problems with this page</a> or contribute a missing <code>spec_url</code> to <a href="https://github.com/mdn/browser-compat-data">mdn/browser-compat-data</a>. Also make sure the specification is included in <a href="https://github.com/w3c/browser-specs">w3c/browser-specs</a>.</p>
</div>
<h2 id="browser_compatibility">Browser compatibility</h2>
<div class="_table"><table>
<thead>
<tr id="bct-browser-type">
<th></th>
<th colspan="6">Desktop</th>
<th colspan="6">Mobile</th>
</tr>
<tr id="bct-browsers">
<th></th>
<th>Chrome</th>
<th>Edge</th>
<th>Firefox</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
<th>WebView Android</th>
<th>Chrome Android</th>
<th>Firefox for Android</th>
<th>Opera Android</th>
<th>Safari on IOS</th>
<th>Samsung Internet</th>
</tr>
</thead>
<tbody>
<tr>
<th><code>type</code></th>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">12</td>
<td class="bc-supports-yes">1</td>
<td class="bc-supports-yes">Yes</td>
<td class="bc-supports-yes">15</td>
<td class="bc-supports-yes">≤4</td>
<td class="bc-supports-yes">4.4</td>
<td class="bc-supports-yes">18</td>
<td class="bc-supports-yes">4</td>
<td class="bc-supports-yes">14</td>
<td class="bc-supports-yes">≤3.2</td>
<td class="bc-supports-yes">1.0</td>
</tr>
<tr>
<th><code>importmap</code></th>
<td class="bc-supports-yes">89</td>
<td class="bc-supports-yes">89</td>
<td class="bc-supports-yes">108</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">75</td>
<td class="bc-supports-yes">16.4</td>
<td class="bc-supports-yes">89</td>
<td class="bc-supports-yes">89</td>
<td class="bc-supports-yes">108</td>
<td class="bc-supports-yes">63</td>
<td class="bc-supports-yes">16.4</td>
<td class="bc-supports-yes">15.0</td>
</tr>
<tr>
<th><code>module</code></th>
<td class="bc-supports-yes"><details><summary>61</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details></td>
<td class="bc-supports-yes">
<details><summary>79</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details>16–79</td>
<td class="bc-supports-yes">60</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes"><details><summary>48</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details></td>
<td class="bc-supports-yes"><details><summary>10.1</summary>Module scripts do not load when the page is served as XHTML (<code>application/xhtml+xml</code>).</details></td>
<td class="bc-supports-yes"><details><summary>61</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details></td>
<td class="bc-supports-yes"><details><summary>61</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details></td>
<td class="bc-supports-yes">60</td>
<td class="bc-supports-yes"><details><summary>45</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details></td>
<td class="bc-supports-yes"><details><summary>10.3</summary>Module scripts do not load when the page is served as XHTML (<code>application/xhtml+xml</code>).</details></td>
<td class="bc-supports-yes"><details><summary>8.0</summary>Module scripts without the <code>async</code> attribute do not load when the page is served as XHTML (<code>application/xhtml+xml</code>). See <a href="https://crbug.com/717643">bug 717643</a>.</details></td>
</tr>
<tr>
<th><code>speculationrules</code></th>
<td class="bc-supports-yes">109<details><summary>105</summary>Initial support included same-origin prerendering only.</details>
</td>
<td class="bc-supports-yes">109<details><summary>105</summary>Initial support included same-origin prerendering only.</details>
</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">95<details><summary>91</summary>Initial support included same-origin prerendering only.</details>
</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">109<details><summary>103</summary>Initial support included same-origin prerendering only.</details>
</td>
<td class="bc-supports-yes">109<details><summary>103</summary>Initial support included same-origin prerendering only.</details>
</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">74<details><summary>71</summary>Initial support included same-origin prerendering only.</details>
</td>
<td class="bc-supports-no">No</td>
<td class="bc-supports-yes">21.0<details><summary>20.0</summary>Initial support included same-origin prerendering only.</details>
</td>
</tr>
</tbody>
</table></div><div class="_attribution">
  <p class="_attribution-p">
    &copy; 2005&ndash;2023 MDN contributors.<br>Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.<br>
    <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type</a>
  </p>
</div>