Script defer attribute

Definition and Usage

defer whether the script should be executed when the page parsing is completed.

This attribute reflects <script> tag of defer attribute.

Note:The defer attribute is only applicable to external scripts (and should only be used when setting the src attribute).

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 completed
  • If neither async nor defer is present: Get and execute the script immediately before the browser continues parsing the page

See also:

HTML Reference Manual:HTML <script> defer Attribute

HTML Reference Manual:HTML <script> Tag

Example

Determine if the script was executed when the page parsing was completed:

var x = document.getElementById("myScript").defer

Try it yourself

Syntax

Return defer attribute:

scriptObject.defer

Set defer attribute:

scriptObject.defer = true|false

attribute value

value description
true|false

Specifies whether the script should be executed when the page is fully parsed.

  • true - The script is executed when the page is fully parsed
  • false - The script will not be executed after the page is fully parsed

Technical Details

Return Value: Boolean value, returns true if the script is executed after the page is fully parsed; otherwise returns false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support