YouTip LogoYouTip

Prop Script Async

HTML DOM Script async Property

HTML DOM Script async Property

-- Learning more than just technology, but dreams!

JavaScript Reference Manual

Overview

JavaScript Objects

Browser Objects

DOM Objects

HTML Objects

HTML DOM Script Object

HTML DOM Script character Property

Script async Property

Image 8: Script Object Reference Manual Script Object

Example

Check if the script is executed asynchronously (as soon as it is available):

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

x output result:

true

Try it yourself Β»


Definition and Usage

The async property sets or returns whether a script should be executed asynchronously (as soon as it is available).

This property reflects the async attribute of the <script> tag.

Note: The async property only applies to external scripts (only when the src attribute is used).

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

  • If async="async": The script is executed asynchronously with respect to the rest of the page (the script will be executed as soon as it is available 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

Image 9: Internet ExplorerImage 10: FirefoxImage 11: OperaImage 12: Google ChromeImage 13: Safari

All major browsers support the async property.

Note: IE 9 and earlier versions, and Opera 12 and earlier versions do not support the async property.


Syntax

Return the async property:

scriptObject.async 

Set the async property:

scriptObject.async=true|false

Property Values

Value Description
true|false Specifies whether the script should be executed asynchronously (as soon as it is available).
* true - The script is executed asynchronously (as soon as it is available). The script will be executed asynchronously as soon as it is available
* false - The script is not executed asynchronously (as soon as it is available).

Technical Details

Return Value: A Boolean. Returns true if the script is executed asynchronously (as soon as it is available), otherwise false.

Related Articles

HTML Reference Manual: HTML <script> async Attribute


Image 14: Script Object Reference Manual Script Object

← Prop Script CharacterDom Obj Script β†’