HTML and script and async properties

HTML script async property HTML and script.html

The js script in the label defaults to synchronous, and you can change how the script is executed by using the async property, refer to the following example:

Once the script is available, it runs asynchronously:

<script src="demo_async.js" async></script>

Try it out . . .

Browser support

HTML script async property HTML script async property HTML script async property HTML script async property HTML script async property

Internet Explorer 10, Firefox, Opera, Chrome, and Safari support async properties.

Note: Internet Explorer 9 and previous versions do not support the async property of the label.


Definitions and usages

The async property is a Boolean property.

Once the async property is available, it is executed asynchronously.

Note: The async 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

The difference between HTML 4.01 and HTML5

The async property is a new property in HTML5.


The difference between HTML and XHTML

In XHTML, properties are prohibited from minimizing, and the async property must be defined as .lt;script async."async".


Grammar

<script async>

HTML script async property HTML and script.html