Script async attribute
Definition and Usage
async
the attribute settings or returns whether the script should be executed asynchronously as soon as it is available.
This attribute reflects <script> tag of async attribute.
Note:The async attribute is only applicable to external scripts (and should only be used when the src attribute is set).
Note:There are several ways to execute external scripts:
- If async is present: The script is executed asynchronously with the rest of the page (the script will be executed while the page continues to parse)
- If async is not present and defer is present: Execute the script when the page parsing is complete
- If neither async nor defer is present: Fetch and execute the script immediately before the browser continues parsing the page
See also:
HTML Reference Manual:HTML <script> async Attribute
HTML Reference Manual:HTML <script> Tag
Example
Check if the script is executed asynchronously as soon as it is available:
var x = document.getElementById("myScript").async
Syntax
Return the async attribute:
scriptObject.async
Set the async attribute:
scriptObject.async = true|false
Attribute value
Value | Description |
---|---|
true|false |
Specify whether the script should be executed asynchronously as soon as it is available.
|
Technical Details
Return Value: | Boolean value, returns true if the script is executed asynchronously as soon as it is available; otherwise returns false. |
---|
Browser Support
The numbers in the table indicate the first browser version to fully support this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |