async Attribute for Script
Example
Check if the script executes asynchronously (as soon as it is available):
x Output result is:
Definition and Usage
The async attribute sets or returns whether the script executes asynchronously (as soon as it is available).
This attribute reflects the async attribute of the <script> tag.
Note: The async attribute is only applicable to external scripts (only when the src attribute is used).
Note: There are several ways to execute external scripts:
If
async="async": The script executes asynchronously with the rest of the page (the script will be executed while the page continues to parse)If
asyncis not used anddefer="defer": The script will be executed when the page has finished parsingIf neither
asyncnordeferis used: The script is fetched and executed immediately, before the browser continues parsing the page
Browser Support
All major browsers support the async attribute.
Note: IE 9 and earlier versions, and Opera 12 and earlier versions do not support the async attribute.
Syntax
Return the async attribute:
Set the async attribute:
Attribute Values
| Value | Description |
|---|---|
| true/false | Specifies whether the script executes asynchronously (as soon as it is available). true - The script will be executed asynchronously as soon as it is available. false - The script will not be executed asynchronously (as soon as it is available). |
Technical Details
| Return Value: | Boolean, returns true if the script executes asynchronously (as soon as it is available), otherwise returns false. |
Related Articles
HTML Reference: HTML <script> async Attribute