In the What is JavaScript tutorial, it says:
Async scripts will download the script without blocking rendering the page and will execute it as soon as the script finishes downloading. You get no guarantee that scripts will run in any specific order, only that they will not stop the rest of the page from displaying. It is best to use
async
when the scripts in the page run independently from each other and depend on no other script on the page.
I am not sure what script that I outlined in bold means. Does they mean the JavaScripts inside <script>
, or any scripts within the document (including HTML and CSS)?
I feel like it is talking about the later. But if that is the case, I am confused. If there is no HTML, what can the JavaScripts operate on?
And if it does mean the later, just to be clear, are the below understandings correct?
-
async
: The browser loads whatever HTML, CSS, and other JavaScript are in the .html file while it is downloading the external .js file withasync
, and loads the .js file once they finish downloading. -
defer
: The browser loads whatever HTML, CSS, and other JavaScript are in the .html file while it is downloading the external .js file withdefer
. But it only loads the .js file after the rest HTML, CSS, other JavaScripts withoutdefer
, and other JavaScripts withdefer
that goes before the current JavaScript is loaded.