0% found this document useful (0 votes)
28 views2 pages

Script Tag

The document explains how browsers handle script tags during HTML parsing, noting that script tags are blocking and pause HTML rendering until the script is downloaded and executed. It also describes how adding the 'async' keyword allows scripts to download in another thread without blocking, while the 'defer' keyword delays script execution until after HTML parsing is complete. This highlights the differences in script loading and execution strategies to optimize web performance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Script Tag

The document explains how browsers handle script tags during HTML parsing, noting that script tags are blocking and pause HTML rendering until the script is downloaded and executed. It also describes how adding the 'async' keyword allows scripts to download in another thread without blocking, while the 'defer' keyword delays script execution until after HTML parsing is complete. This highlights the differences in script loading and execution strategies to optimize web performance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 2

-> the browser starts parsing the html code.

-> when it comes across a script tag in the head section, the
parsing is paused.

-> An http request is sent to the server to fetch the script.


-> the browser wait until the entire script is downloaded.

-> It then does the work of parsing, interpreting and executing the
downloaded script.
-> this happens for each of the script tag.

-> once all this done, the browser resumes its work of parsing
HTML and creating DOM nodes.
-> Script tags are blocking in nature. They block the rendering of
the DOM.

Downloading script asynchronously?

-> when we add async keyword in js script tag, the script is


downloaded in another thread without disturbing the main thread.
-> once its downloaded, the browser pauses the parsing of HTML
and gets busy in parsing the script code.
-> once the parsing of this JS is completed, it is executed in
another thread, and the browser resumes its work of parsing the
html.

Deferring the Execution of Scripts.


-> When add defer keyword in script tag, the browser doesn’t
executes that script until the HTML parsing is completed.
-> defer simply means the execution of the file is deferred or
delayed.
-> The script is downloaded in another thread and is executed only
after the HTML parsing is completed.

You might also like