JavaScript Loading Strategies in Web Page: async and defer
Understanding the Performance Implications of async and defer Attributes

A lifelong learner. Love to travel. Listen to music.
Search for a command to run...
Understanding the Performance Implications of async and defer Attributes

A lifelong learner. Love to travel. Listen to music.
No comments yet. Be the first to comment.
Overview static: Default position. It does not allow setting properties like top, bottom, left, right, z-index relative: Acts the same as static. but allows positioning it relatively by putting properties like top, bottom, left, right, z-index absolu...
Best Practices for Path Structure, Versioning, and Error Handling

Overview static: Default position. It does not allow setting properties like top, bottom, left, right, z-index relative: Acts the same as static. but allows positioning it relatively by putting properties like top, bottom, left, right, z-index absolu...

Overview When an element in the browser has a conflict of styles, the browser uses a set of rules to determine which style should be rendered. This set of rules is defined as CSS Selector Specificity. For instance, for an element, if we have the foll...

Master block, inline, flex, and grid to build better web layouts

<script> tags are used to download and execute JavaScript on a web page.
Consider these three operations on a web page:
HTML Parsing
JavaScript Download
JavaScript Execution
We can manipulate the sequence of these phases using the following attributes in the <script> tag:
async (<script async src=''></script>)
defer (<script defer src=''></script>)
By default (<script src=''></script>), the script tag blocks HTML parsing until the JavaScript is downloaded and executed. This means that the browser will stop parsing the HTML, download the script, execute it, and then resume parsing the HTML.
async and defer Behavior:Both async and defer do not block HTML parsing during the JavaScript download. The script download and HTML parsing happen simultaneously.
defer ensures that the JavaScript is executed after the HTML parsing is completed. This means that all deferred scripts are executed in the order they appear in the document, but only after the entire HTML has been parsed.
async ensures that the JavaScript is executed as soon as it is downloaded, without waiting for the HTML parsing to complete. This can result in the script executing before, during, or after HTML parsing, potentially interrupting it.

Default: JS Download → Execute → HTML Parse
Defer: (HTML Parse + JS Download in Parallel) → JS Execute (after parsing)
Async: HTML Parse + (JS Download → JS Execute when ready, possibly mid-parse)
Use Case
Use async, when a script has no dependency on others
Use defer when the script depends on other scripts
References: