Script asyncProperties

Script 对象参考手册Script Object

Examples

Check whether the script executes asynchronously (as soon as it is available):

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

xThe output result is:

true

Try it yourself »

Definition and Usage

The async property sets or returns whether the script is executed asynchronously (once the script is available).

This property 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 is executed asynchronously with the rest of the page (the script will be executed while the page continues parsing)
  • If async is not used and defer="defer": the script will be executed when the page has finished parsing
  • If neither async nor defer is used: the script is read and executed immediately before the browser continues parsing the page

Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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 property:

scriptObject.async

Set the async property:

scriptObject.async=true|false

Property Values

Value Description
true|false Specifies whether to execute the script asynchronously (once the script is available).
  • true - Execute the script asynchronously (once the script is available). The script will be executed asynchronously as soon as it is available
  • false - The script will not be executed asynchronously (once the script is available).

Technical Details

Return value: A Boolean value, returns true if the script is executed asynchronously (once the script is available), otherwise returns false.


Related Articles

HTML Reference Manual:HTML <script> async Attribute


Script 对象参考手册Script Object

Other Extensions