How to mark script element as Asynchronous

Description

async which applies only to external scripts changes the way the script is processed.

It signals the browser to begin downloading the file immediately.

async scripts are not guaranteed to execute in the order in which they are specified.

Example


<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" async src="example1.js"></script>
    <script type="text/javascript" async src="example2.js"></script>
</head>
<body>
       <!-- content here -->
</body>
</html>

Note

In this code, the second script file might execute before the first.

For XHTML documents, specify the async attribute as async="async".





















Home »
  Javascript »
    Javascript Introduction »




Script Element
Syntax
Data Type
Operator
Statement
Array
Primitive Wrapper Types
Function
Object-Oriented
Date
DOM
JSON
Regular Expressions