defer Attribute
Example
Check if the script executes when the page finishes parsing:
x Output result:
Definition and Usage
The defer attribute sets or returns whether the script should execute when the page finishes parsing.
This attribute reflects the defer attribute of the <script> tag.
Note: The defer 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 is executed 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 finishes 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 defer attribute.
Note: Opera 12 and earlier versions do not support the defer attribute.
Syntax
Return the defer attribute:
Set the defer attribute:
Attribute Values
| Value | Description |
|---|---|
| true/false | Specifies whether the script should execute when the page finishes parsing. true - The script executes when the page finishes parsing.<br>false - The script does not execute when the page finishes parsing. |
Technical Details
| Return Value: | Boolean, returns true if the script executes when the page finishes parsing, otherwise returns false. | | --- | --- |
Related Articles
HTML Reference: HTML <script> defer Attribute