0% found this document useful (0 votes)
18 views

Script Tag

Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Script Tag

Copyright
© © All Rights Reserved
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