async attribute is a boolean that determines whether the script should be fetched asynchronously.
async Attribute can be used with the following elements:
async attribute is a boolean that determines whether the script should be fetched asynchronously. This means it is fetched in parallel to HTML parsing and evaluated as soon as possible.
<script async src="https://cdn.ampproject.org/v0.js"></script>
asyncattribute is a boolean.
srcattribute must be present. The
asyncattribute only applies to external scripts.
There are two different types of scripts:
- For normal scripts, if the
asyncattribute is present, it will be fetched in parallel to parsing and evaluated as soon as possible.
- For module scripts, if the
asyncattribute is present, it will fetch the script along with all its dependencies in parallel to parsing and evaluate them as soon as possible.
There are several ways you can execute an external script:
asynconly, then they are fetched as set out above.
asyncis not present, but
deferis present, then the script is executed after the page has finished parsing. See the
deferattribute for more details.
- If neither
deferis present, then the script is fetched and executed immediately before the browser continues parsing the rest of the page.
Values can include:
<script async src="/examples/async.js"></script>
The following example loads
<script> element with the
type=module, and sets a standard fallback script using the
nomodule attribute. The
nomodule attribute is ignored by any browser that supports modules.
<script async src="script.js"></script> <script nomodule async src="backupscript.js"></script>
async HTML specification for the
<script> element is as follows:
async has the following browser support:
|Android Webview||Chrome Android||Firefox Android||Opera Android||iOS Safari||Samsung Internet|