Script Execution: Normal, Asynchronous, and Deferred

Normal Execution

By default, JavaScript files will interrupt the parsing of the HTML document in order for them to be fetched (if not inline) and executed.

<head> ... </head>
<script src="script.js">

The async Attribute

The async attribute is used to indicate to the browser that the script file can be executed asynchronously. The HTML parser does not need to pause at the point it reaches the script tag to fetch and execute, the execution can happen whenever the script becomes ready after being fetched in parallel with the document parsing.

<script async src="script.js">

The defer Attribute

The defer attribute tells the browser to only execute the script file once the HTML document has been fully parsed.

<script defer src="script.js">



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhay Jain

Abhay Jain

Developer with 3 yrs of industrial experience in developing scalable web applications.