Asynchronous Scripts

The async attribute applies only to external scripts. It signals the browser to begin downloading the file immediately. The scripts marked as async are not guaranteed to execute in the specified order.

 
<!DOCTYPE html> 
<html> 
<head> 
<title>Example HTML Page</title> 
    <script type="text/javascript" async src="example1.js"></script> 
    <script type="text/javascript" async src="example2.js"></script> 
</head> 
<body> 
</body> 
</html>
  
Click to view the demo

In this code, the second script file might execute before the first. For XHTML documents, specify the async attribute as async="async".

Home 
  JavaScript Book 
    Language Basics  

Script Element:
  1. Getting Ready to Use JavaScript and <SCRIPT> ELEMENT
  2. Deferred Scripts
  3. Asynchronous Scripts
  4. <NOSCRIPT> ELEMENT
  5. Using Statements