Consider the following scenario:
<h1>Hello!</h1>
<script src="cool1.js"></script>
<script src="cool2.js"></script>
<h2>Goodbye!</h2>
<img src="boat.gif" alt="Big Boat">
When cool1.js
is being downloaded does that mean that Hello!
has been displayed but Goodbye!
will not be displayed until cool1.js
downloads AND executes?
When will cool2.js
download (I know JavaScript is single threaded so it has to wait for cool1.js
to finish executing)? When will boat.gif
download and display?
Here the author claims:
The browser can only be executing JavaScript or rendering UI at any particular point in time ... think of what happens as a page downloads to the browser. The page has started to render as it was downloaded, and then a tag is encountered. At that point, the browser can no longer continue rendering because the JavaScript may affect the UI, and so it waits.
I don't get this because couldn't JavaScript modify content that came before it?
For example what if cool1.js
changed the contents inside <h1>
to say "Good day"?