summaryrefslogtreecommitdiff
path: root/devdocs/html/element%2Fscript.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/html/element%2Fscript.html
new repository
Diffstat (limited to 'devdocs/html/element%2Fscript.html')
-rw-r--r--devdocs/html/element%2Fscript.html361
1 files changed, 361 insertions, 0 deletions
diff --git a/devdocs/html/element%2Fscript.html b/devdocs/html/element%2Fscript.html
new file mode 100644
index 00000000..27283eb7
--- /dev/null
+++ b/devdocs/html/element%2Fscript.html
@@ -0,0 +1,361 @@
+<header><h1>&lt;script&gt;: The Script element</h1></header><div class="section-content">
+<p>The <code>&lt;script&gt;</code> <a href="../index">HTML</a> element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code. The <code>&lt;script&gt;</code> element can also be used with other languages, such as <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API">WebGL</a>'s GLSL shader programming language and <a href="https://developer.mozilla.org/en-US/docs/Glossary/JSON">JSON</a>.</p> <figure class="table-container"><div class="_table"><table class="properties"> <tbody> <tr> <th scope="row"><a href="../content_categories">Content categories</a></th> <td> <a href="../content_categories#metadata_content">Metadata content</a>, <a href="../content_categories#flow_content">Flow content</a>, <a href="../content_categories#phrasing_content">Phrasing content</a>. </td> </tr> <tr> <th scope="row">Permitted content</th> <td>Dynamic script such as <code>text/javascript</code>.</td> </tr> <tr> <th scope="row">Tag omission</th> <td>None, both the starting and ending tag are mandatory.</td> </tr> <tr> <th scope="row">Permitted parents</th> <td> Any element that accepts <a href="../content_categories#metadata_content">metadata content</a>, or any element that accepts <a href="../content_categories#phrasing_content">phrasing content</a>. </td> </tr> <tr> <th scope="row">Implicit ARIA role</th> <td><a href="https://www.w3.org/TR/html-aria/#dfn-no-corresponding-role" target="_blank">No corresponding role</a></td> </tr> <tr> <th scope="row">Permitted ARIA roles</th> <td>No <code>role</code> permitted</td> </tr> <tr> <th scope="row">DOM interface</th> <td><a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement"><code>HTMLScriptElement</code></a></td> </tr> </tbody> </table></div></figure>
+</div>
+<h2 id="attributes">Attributes</h2>
+<div class="section-content">
+<p>This element includes the <a href="../global_attributes">global attributes</a>.</p> <dl> <dt id="async"><a href="#async"><code>async</code></a></dt> <dd> <p>For classic scripts, if the <code>async</code> attribute is present, then the classic script will be fetched in parallel to parsing and evaluated as soon as it is available.</p> <p>For <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">module scripts</a>, if the <code>async</code> attribute is present then the scripts and all their dependencies will be fetched in parallel to parsing and evaluated as soon as they are available.</p> <p>This attribute allows the elimination of <strong>parser-blocking JavaScript</strong> where the browser would have to load and evaluate scripts before continuing to parse. <code>defer</code> has a similar effect in this case.</p> <p>This is a boolean attribute: the presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.</p> <p>See <a href="#browser_compatibility">Browser compatibility</a> for notes on browser support. See also <a href="https://developer.mozilla.org/en-US/docs/Games/Techniques/Async_scripts">Async scripts for asm.js</a>.</p> </dd> <dt id="blocking">
+<a href="#blocking"><code>blocking</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 attribute explicitly indicates that certain operations should be blocked on the fetching of the script. The operations that are to be blocked must be a space-separated list of blocking attributes listed below.</p> <ul> <li>
+<code>render</code>: The rendering of content on the screen is blocked.</li> </ul> </dd> <dt id="crossorigin"><a href="#crossorigin"><code>crossorigin</code></a></dt> <dd> <p>Normal <code>script</code> elements pass minimal information to the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/error_event"><code>window.onerror</code></a> for scripts which do not pass the standard <a href="https://developer.mozilla.org/en-US/docs/Glossary/CORS">CORS</a> checks. To allow error logging for sites which use a separate domain for static media, use this attribute. See <a href="../attributes/crossorigin">CORS settings attributes</a> for a more descriptive explanation of its valid arguments.</p> </dd> <dt id="defer"><a href="#defer"><code>defer</code></a></dt> <dd> <p>This Boolean attribute is set to indicate to a browser that the script is meant to be executed after the document has been parsed, but before firing <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event"><code>DOMContentLoaded</code></a>.</p> <p>Scripts with the <code>defer</code> attribute will prevent the <code>DOMContentLoaded</code> event from firing until the script has loaded and finished evaluating.</p> <div class="notecard warning" id="sect1"> <p><strong>Warning:</strong> This attribute must not be used if the <code>src</code> attribute is absent (i.e. for inline scripts), in this case it would have no effect.</p> <p>The <code>defer</code> attribute has no effect on <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">module scripts</a> — they defer by default.</p> </div> <p>Scripts with the <code>defer</code> attribute will execute in the order in which they appear in the document.</p> <p>This attribute allows the elimination of <strong>parser-blocking JavaScript</strong> where the browser would have to load and evaluate scripts before continuing to parse. <code>async</code> has a similar effect in this case.</p> </dd> <dt id="fetchpriority">
+<a href="#fetchpriority"><code>fetchpriority</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>Provides a hint of the relative priority to use when fetching an external script. Allowed values:</p> <dl> <dt id="high"><a href="#high"><code>high</code></a></dt> <dd> <p>Signals a high-priority fetch relative to other external scripts.</p> </dd> <dt id="low"><a href="#low"><code>low</code></a></dt> <dd> <p>Signals a low-priority fetch relative to other external scripts.</p> </dd> <dt id="auto"><a href="#auto"><code>auto</code></a></dt> <dd> <p>Default: Signals automatic determination of fetch priority relative to other external scripts.</p> </dd> </dl> </dd> <dt id="integrity"><a href="#integrity"><code>integrity</code></a></dt> <dd> <p>This attribute contains inline metadata that a user agent can use to verify that a fetched resource has been delivered free of unexpected manipulation. See <a href="https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity">Subresource Integrity</a>.</p> </dd> <dt id="nomodule"><a href="#nomodule"><code>nomodule</code></a></dt> <dd> <p>This Boolean attribute is set to indicate that the script should not be executed in browsers that support <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">ES modules</a> — in effect, this can be used to serve fallback scripts to older browsers that do not support modular JavaScript code.</p> </dd> <dt id="nonce"><a href="#nonce"><code>nonce</code></a></dt> <dd> <p>A cryptographic nonce (number used once) to allow scripts in a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src">script-src Content-Security-Policy</a>. The server must generate a unique nonce value each time it transmits a policy. It is critical to provide a nonce that cannot be guessed as bypassing a resource's policy is otherwise trivial.</p> </dd> <dt id="referrerpolicy"><a href="#referrerpolicy"><code>referrerpolicy</code></a></dt> <dd> <p>Indicates which <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer">referrer</a> to send when fetching the script, or resources fetched by the script:</p> <ul> <li>
+<code>no-referrer</code>: The <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer"><code>Referer</code></a> header will not be sent.</li> <li>
+<code>no-referrer-when-downgrade</code>: The <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer"><code>Referer</code></a> header will not be sent to <a href="https://developer.mozilla.org/en-US/docs/Glossary/Origin">origin</a>s without <a href="https://developer.mozilla.org/en-US/docs/Glossary/TLS">TLS</a> (<a href="https://developer.mozilla.org/en-US/docs/Glossary/HTTPS">HTTPS</a>).</li> <li>
+<code>origin</code>: The sent referrer will be limited to the origin of the referring page: its <a href="https://developer.mozilla.org/en-US/docs/Learn/Common_questions/Web_mechanics/What_is_a_URL">scheme</a>, <a href="https://developer.mozilla.org/en-US/docs/Glossary/Host">host</a>, and <a href="https://developer.mozilla.org/en-US/docs/Glossary/Port">port</a>.</li> <li>
+<code>origin-when-cross-origin</code>: The referrer sent to other origins will be limited to the scheme, the host, and the port. Navigations on the same origin will still include the path.</li> <li>
+<code>same-origin</code>: A referrer will be sent for <a href="https://developer.mozilla.org/en-US/docs/Glossary/Same-origin_policy">same origin</a>, but cross-origin requests will contain no referrer information.</li> <li>
+<code>strict-origin</code>: Only send the origin of the document as the referrer when the protocol security level stays the same (HTTPS→HTTPS), but don't send it to a less secure destination (HTTPS→HTTP).</li> <li>
+<code>strict-origin-when-cross-origin</code> (default): Send a full URL when performing a same-origin request, only send the origin when the protocol security level stays the same (HTTPS→HTTPS), and send no header to a less secure destination (HTTPS→HTTP).</li> <li>
+<code>unsafe-url</code>: The referrer will include the origin <em>and</em> the path (but not the <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/hash">fragment</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/password">password</a>, or <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLAnchorElement/username">username</a>). <strong>This value is unsafe</strong>, because it leaks origins and paths from TLS-protected resources to insecure origins.</li> </ul> <div class="notecard note" id="sect2"> <p><strong>Note:</strong> An empty string value (<code>""</code>) is both the default value, and a fallback value if <code>referrerpolicy</code> is not supported. If <code>referrerpolicy</code> is not explicitly specified on the <code>&lt;script&gt;</code> element, it will adopt a higher-level referrer policy, i.e. one set on the whole document or domain. If a higher-level policy is not available, the empty string is treated as being equivalent to <code>strict-origin-when-cross-origin</code>.</p> </div> </dd> <dt id="src"><a href="#src"><code>src</code></a></dt> <dd> <p>This attribute specifies the URI of an external script; this can be used as an alternative to embedding a script directly within a document.</p> </dd> <dt id="sect3"><a href="script/type"><code>type</code></a></dt> <dd> <p> This attribute indicates the type of script represented. The value of this attribute 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="sect4"><a href="script/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="sect5">
+<a href="script/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> </dd> </dl>
+</div>
+<h3 id="deprecated_attributes">Deprecated attributes</h3>
+<div class="section-content"><dl> <dt id="charset">
+<a href="#charset"><code>charset</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr>
+</dt> <dd> <p>If present, its value must be an <a href="https://developer.mozilla.org/en-US/docs/Glossary/ASCII">ASCII</a> case-insensitive match for "<code>utf-8</code>". It's unnecessary to specify the <code>charset</code> attribute, because documents must use UTF-8, and the <code>script</code> element inherits its character encoding from the document.</p> </dd> <dt id="language">
+<a href="#language"><code>language</code></a> <abbr class="icon icon-deprecated" title="Deprecated. Not for use in new websites."> <span class="visually-hidden">Deprecated</span> </abbr> <abbr class="icon icon-nonstandard" title="Non-standard. Check cross-browser support before using."> <span class="visually-hidden">Non-standard</span> </abbr>
+</dt> <dd> <p>Like the <code>type</code> attribute, this attribute identifies the scripting language in use. Unlike the <code>type</code> attribute, however, this attribute's possible values were never standardized. The <code>type</code> attribute should be used instead.</p> </dd> </dl></div>
+<h2 id="notes">Notes</h2>
+<div class="section-content">
+<p>Scripts without <a href="#async"><code>async</code></a>, <a href="#defer"><code>defer</code></a> or <code>type="module"</code> attributes, as well as inline scripts without the <code>type="module"</code> attribute, are fetched and executed immediately before the browser continues to parse the page.</p> <p> The script should be served with the <code>text/javascript</code> MIME type, but browsers are lenient and only block them if the script is served with an image type (<code>image/*</code>), a video type (<code>video/*</code>), an audio type (<code>audio/*</code>), or <code>text/csv</code>. If the script is blocked, an <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/error_event"><code>error</code></a> event is sent to the element; otherwise, a <a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/load_event"><code>load</code></a> event is sent. </p>
+</div>
+<h2 id="examples">Examples</h2>
+
+<h3 id="basic_usage">Basic usage</h3>
+<div class="section-content">
+<p>These examples show how to import (an external) script using the <code>&lt;script&gt;</code> element.</p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="WL2iP3PQXAZ7+c2DL76Ujc0rBQRjIoXq8yrlyvGe1QA=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>javascript.js<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div> <p>And the following examples show how to put (an inline) script inside the <code>&lt;script&gt;</code> element.</p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="BRn57YYY+rm8KCGVZjolEHCsoPX4ykNAhPEpQnAZTCE=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
+ <span class="token function">alert</span><span class="token punctuation">(</span><span class="token string">"Hello World!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
+</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div>
+</div>
+<h3 id="module_fallback">Module fallback</h3>
+<div class="section-content">
+<p>Browsers that support the <code>module</code> value for the <a href="#type"><code>type</code></a> attribute ignore any script with a <code>nomodule</code> attribute. That enables you to use module scripts while providing <code>nomodule</code>-marked fallback scripts for non-supporting browsers.</p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="cp7LD7t7m517wr8IDlzKh1px9BlCJoE88rX3TMBj62E=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>module<span class="token punctuation">"</span></span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>main.js<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">nomodule</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>fallback.js<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div>
+</div>
+<h3 id="importing_modules_with_importmap">Importing modules with importmap</h3>
+<div class="section-content">
+<p> When importing modules in scripts, if you don't use the <a href="#importmap"><code>type=importmap</code></a> feature, then each module must be imported using a module specifier that is either an absolute or relative URL. In the example below, the first module specifier ("./shapes/square.js") resolves relative to the base URL of the document, while the second is an absolute URL. </p> <div class="code-example">
+<p class="example-header"><span class="language-name">js</span></p>
+<pre data-signature="gXEqEUrcNVdR5bCiOj+b10q6mo7U7GGs1744i1SZZ8c=" data-language="js"><span class="token keyword">import</span> <span class="token punctuation">{</span> name <span class="token keyword">as</span> squareName<span class="token punctuation">,</span> draw <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"./shapes/square.js"</span><span class="token punctuation">;</span>
+<span class="token keyword">import</span> <span class="token punctuation">{</span> name <span class="token keyword">as</span> circleName <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"https://example.com/shapes/circle.js"</span><span class="token punctuation">;</span>
+</pre>
+</div> <p> An import map allows you to provide a mapping that, if matched, can replace the text in the module specifier. The import map below defines keys <code>square</code> and <code>circle</code> that can be used as aliases for the module specifiers shown above. </p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="kKMjrUvbBdFWOvRxvt29mabORhnBe+DFdAVIGFVYGoo=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>importmap<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
+ <span class="token punctuation">{</span>
+ <span class="token string-property property">"imports"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
+ <span class="token string-property property">"square"</span><span class="token operator">:</span> <span class="token string">"./shapes/square.js"</span><span class="token punctuation">,</span>
+ <span class="token string-property property">"circle"</span><span class="token operator">:</span> <span class="token string">"https://example.com/shapes/circle.js"</span>
+ <span class="token punctuation">}</span>
+ <span class="token punctuation">}</span>
+</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div> <p>This allows us to import modules using names in the module specifier (rather than absolute or relative URLs).</p> <div class="code-example">
+<p class="example-header"><span class="language-name">js</span></p>
+<pre data-signature="3z7KTwOPwElmzvBo8T4qhEwW/oNOKzGT6BYzM4NAgYc=" data-language="js"><span class="token keyword">import</span> <span class="token punctuation">{</span> name <span class="token keyword">as</span> squareName<span class="token punctuation">,</span> draw <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"square"</span><span class="token punctuation">;</span>
+<span class="token keyword">import</span> <span class="token punctuation">{</span> name <span class="token keyword">as</span> circleName <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">"circle"</span><span class="token punctuation">;</span>
+</pre>
+</div> <p>For more examples of what you can do with import maps, see the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#importing_modules_using_import_maps">Importing modules using import maps</a> section in the JavaScript modules guide.</p>
+</div>
+<h3 id="embedding_data_in_html">Embedding data in HTML</h3>
+<div class="section-content">
+<p>You can also use the <code>&lt;script&gt;</code> element to embed data in HTML with server-side rendering by specifying a valid non-JavaScript MIME type in the <code>type</code> attribute.</p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="vJ7NhD1+ZiLSNtkVUK7FZEKoZXdtTfmqsXE7k+0s/7Y=" data-language="html"><span class="token comment">&lt;!-- Generated by the server --&gt;</span>
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">id</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>data<span class="token punctuation">"</span></span> <span class="token attr-name">type</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>application/json<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
+ <span class="token punctuation">{</span>
+ <span class="token string-property property">"userId"</span><span class="token operator">:</span> <span class="token number">1234</span><span class="token punctuation">,</span>
+ <span class="token string-property property">"userName"</span><span class="token operator">:</span> <span class="token string">"Maria Cruz"</span><span class="token punctuation">,</span>
+ <span class="token string-property property">"memberSince"</span><span class="token operator">:</span> <span class="token string">"2000-01-01T00:00:00.000Z"</span>
+ <span class="token punctuation">}</span>
+</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+
+<span class="token comment">&lt;!-- Static --&gt;</span>
+<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
+ <span class="token keyword">const</span> userInfo <span class="token operator">=</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">"data"</span><span class="token punctuation">)</span><span class="token punctuation">.</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span>
+ console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">"User information: %o"</span><span class="token punctuation">,</span> userInfo<span class="token punctuation">)</span><span class="token punctuation">;</span>
+</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div>
+</div>
+<h3 id="blocking_rendering_till_a_script_is_fetched_and_executed">Blocking rendering till a script is fetched and executed</h3>
+<div class="section-content">
+<p> You can include <code>render</code> token inside a <code>blocking</code> attribute; the rendering of the page will be blocked till the script is fetched and executed. In the example below, we block rendering on an async script, so that the script doesn't block parsing but is guaranteed to be evaluated before rendering starts. </p> <div class="code-example">
+<p class="example-header"><span class="language-name">html</span></p>
+<pre data-signature="NFlvDEcAnmljjkrp0QZcV/2PS7k6J6Vzu5lNMxxYlpY=" data-language="html"><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span> <span class="token attr-name">blocking</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>render<span class="token punctuation">"</span></span> <span class="token attr-name">async</span> <span class="token attr-name">src</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">"</span>async-script.js<span class="token punctuation">"</span></span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
+</pre>
+</div>
+</div>
+<h2 id="specifications">Specifications</h2>
+<div class="_table"><table class="standard-table">
+<thead><tr><th scope="col">Specification</th></tr></thead>
+<tbody><tr><td><a href="https://html.spec.whatwg.org/multipage/scripting.html#the-script-element">HTML Standard <br><small># the-script-element</small></a></td></tr></tbody>
+</table></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>script</code></th>
+<td class="bc-supports-yes">1</td>
+<td class="bc-supports-yes">12</td>
+<td class="bc-supports-yes"><details><summary>1</summary>Starting in Firefox 4, inserting &lt;script&gt; elements that have been created by calling <code>document.createElement("script")</code> no longer enforces execution in insertion order. This change lets Firefox properly abide by the specification. To make script-inserted external scripts execute in their insertion order, set <code>.async=false</code> on them.</details></td>
+<td class="bc-supports-yes">Yes</td>
+<td class="bc-supports-yes">≤12.1</td>
+<td class="bc-supports-yes">3</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">≤12.1</td>
+<td class="bc-supports-yes">2</td>
+<td class="bc-supports-yes">1.0</td>
+</tr>
+<tr>
+<th><code>async</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>attributionsrc</code></th>
+<td class="bc-supports-yes">117</td>
+<td class="bc-supports-yes">117</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">103</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">117</td>
+<td class="bc-supports-yes">117</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+</tr>
+<tr>
+<th><code>blocking</code></th>
+<td class="bc-supports-yes">105</td>
+<td class="bc-supports-yes">105</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">91</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">105</td>
+<td class="bc-supports-yes">105</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">72</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">20.0</td>
+</tr>
+<tr>
+<th><code>crossorigin</code></th>
+<td class="bc-supports-yes">19</td>
+<td class="bc-supports-yes">14</td>
+<td class="bc-supports-yes">14</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">12</td>
+<td class="bc-supports-yes"><details><summary>6</summary>The <code>crossorigin</code> attribute was implemented in WebKit in WebKit <a href="https://webkit.org/b/81438">bug 81438</a>.</details></td>
+<td class="bc-supports-yes">4.4</td>
+<td class="bc-supports-yes">25</td>
+<td class="bc-supports-yes">14</td>
+<td class="bc-supports-yes">12</td>
+<td class="bc-supports-yes"><details><summary>6</summary>The <code>crossorigin</code> attribute was implemented in WebKit in WebKit <a href="https://webkit.org/b/81438">bug 81438</a>.</details></td>
+<td class="bc-supports-yes">1.5</td>
+</tr>
+<tr>
+<th><code>defer</code></th>
+<td class="bc-supports-yes"><details><summary>1</summary>Chrome does not defer scripts with the <code>defer</code> attribute when the page is served as XHTML (<code>application/xhtml+xml</code>) - <a href="https://crbug.com/611136">Chromium Issue #611136</a>, <a href="https://crbug.com/874749">Chromium Issue #874749</a></details></td>
+<td class="bc-supports-yes">12</td>
+<td class="bc-supports-yes"><details><summary>3.5</summary>Since Firefox 3.6, the <code>defer</code> attribute is ignored on scripts that don't have the <code>src</code> attribute. However, in Firefox 3.5 even inline scripts are deferred if the <code>defer</code> attribute is set.</details></td>
+<td class="bc-supports-yes"><details><summary>10</summary>Before version 10, Internet Explorer implemented <code>defer</code> by a proprietary specification. Since version 10 it conforms to the W3C specification.</details></td>
+<td class="bc-supports-yes"><details><summary>15</summary>Opera does not defer scripts with the <code>defer</code> attribute when the page is served as XHTML (<code>application/xhtml+xml</code>) - <a href="https://crbug.com/611136">Chromium Issue #611136</a>, <a href="https://crbug.com/874749">Chromium Issue #874749</a></details></td>
+<td class="bc-supports-yes">3</td>
+<td class="bc-supports-yes"><details><summary>4.4</summary>Chrome does not defer scripts with the <code>defer</code> attribute when the page is served as XHTML (<code>application/xhtml+xml</code>) - <a href="https://crbug.com/611136">Chromium Issue #611136</a>, <a href="https://crbug.com/874749">Chromium Issue #874749</a></details></td>
+<td class="bc-supports-yes"><details><summary>18</summary>Chrome does not defer scripts with the <code>defer</code> attribute when the page is served as XHTML (<code>application/xhtml+xml</code>) - <a href="https://crbug.com/611136">Chromium Issue #611136</a>, <a href="https://crbug.com/874749">Chromium Issue #874749</a></details></td>
+<td class="bc-supports-yes">4</td>
+<td class="bc-supports-yes"><details><summary>14</summary>Opera does not defer scripts with the <code>defer</code> attribute when the page is served as XHTML (<code>application/xhtml+xml</code>) - <a href="https://crbug.com/611136">Chromium Issue #611136</a>, <a href="https://crbug.com/874749">Chromium Issue #874749</a></details></td>
+<td class="bc-supports-yes">2</td>
+<td class="bc-supports-yes"><details><summary>1.0</summary>Samsung Internet does not defer scripts with the <code>defer</code> attribute when the page is served as XHTML (<code>application/xhtml+xml</code>) - <a href="https://crbug.com/611136">Chromium Issue #611136</a>, <a href="https://crbug.com/874749">Chromium Issue #874749</a></details></td>
+</tr>
+<tr>
+<th><code>fetchpriority</code></th>
+<td class="bc-supports-yes">101</td>
+<td class="bc-supports-yes">101</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">preview</td>
+<td class="bc-supports-yes">101</td>
+<td class="bc-supports-yes">101</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">70</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">19.0</td>
+</tr>
+<tr>
+<th><code>integrity</code></th>
+<td class="bc-supports-yes">45</td>
+<td class="bc-supports-yes">17</td>
+<td class="bc-supports-yes">43</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">32</td>
+<td class="bc-supports-yes">11.1</td>
+<td class="bc-supports-yes">45</td>
+<td class="bc-supports-yes">45</td>
+<td class="bc-supports-yes">43</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">11.3</td>
+<td class="bc-supports-yes">5.0</td>
+</tr>
+<tr>
+<th><code>language</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>nomodule</code></th>
+<td class="bc-supports-yes">61</td>
+<td class="bc-supports-yes">16</td>
+<td class="bc-supports-yes">60</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">48</td>
+<td class="bc-supports-yes">11</td>
+<td class="bc-supports-yes">61</td>
+<td class="bc-supports-yes">61</td>
+<td class="bc-supports-yes">60</td>
+<td class="bc-supports-yes">45</td>
+<td class="bc-supports-yes">11</td>
+<td class="bc-supports-yes">8.0</td>
+</tr>
+<tr>
+<th><code>referrerpolicy</code></th>
+<td class="bc-supports-yes">70</td>
+<td class="bc-supports-yes">≤79</td>
+<td class="bc-supports-yes">65</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">57</td>
+<td class="bc-supports-yes">14</td>
+<td class="bc-supports-yes">70</td>
+<td class="bc-supports-yes">70</td>
+<td class="bc-supports-yes">65</td>
+<td class="bc-supports-no">No</td>
+<td class="bc-supports-yes">14</td>
+<td class="bc-supports-yes">10.0</td>
+</tr>
+<tr>
+<th><code>src</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>text</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>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>
+</tbody>
+</table></div>
+<h2 id="see_also">See also</h2>
+<div class="section-content"><ul> <li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/currentScript"><code>document.currentScript</code></a></li> <li><a href="https://flaviocopes.com/javascript-async-defer/" target="_blank">Flavio Copes' article on loading JavaScript efficiently and explaining the differences between <code>async</code> and <code>defer</code></a></li> <li>
+<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules">JavaScript modules</a> guide</li> </ul></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" class="_attribution-link">https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script</a>
+ </p>
+</div>