Script defer property

HTML DOM Script defer property Script object

Check if the script is executed when the page is resolved:

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

x The output is:

true

Try it out . . .

Definitions and usages

The defer property is set or returns whether the script is executed when the page is resolved.

This property reflects the defer property of the label.

Note: The defer property applies only to external scripts (only when using the src property).

Note: There are several ways to execute an external script:

  • If async is "async": The script executes asynchronously relative to the rest of the page (the script is executed as the page continues to parse)
  • If you do not use async and defer is "defer": the script will execute when the page is resolved
  • If you do not use async or defer: Read and execute the script immediately before the browser continues to parse the page

Browser support

HTML DOM Script defer property HTML DOM Script defer property HTML DOM Script defer property HTML DOM Script defer property HTML DOM Script defer property

The defer property is supported by all major browsers.

Note: Opera 12 and its previous versions do not support the defer property.


Grammar

Returns the defer property:

scriptObject .defer

Set the defer property:

scriptObject .defer=true|false

The property value

value describe
true|false Specifies whether a script is executed when the page is completed.
  • TRUE - executes the script when the page is completed.
  • False - Do not perform scripts when the page is completed.

Technical details

Return value: Boolean value, if the script is executed when the page is resolved, returns true, otherwise false.


Related articles

HTML Reference Manual: HTML slt;script> defer properties


HTML DOM Script defer property Script object