I use cuzillion tool build a page:
<head>
<script async></script>
</head>
<body>
<img />
<img />
<img />
</body>
there is only one script element in head, with async attribute and 2 second delay, 3 second to execute.
but the page load timeline in Chrome is:
when the script executing, it still block the browser render process?
But why? it shouldn't execute asynchronously?
However it doesn't block the parser:
The execution of any script always blocks parsing, rendering, and execution of other scripts in the same tab. The attribute async
does not change that.
The only thing async
does is tell the browser that the script should be fetched (assuming it's a remote file) without blocking those activities.
After the script is downloaded, the script starts executing at the next available opportunity (that is, right after the current script, if any, finishes running; a new script won't, of course, interrupt a running script). Once that happens, your rendering is blocked. So, with a fast web server, downloading happens so fast that async
makes no difference at all.
If you don't want your scripts to pause rendering, use defer
attribute instead of async
. That will delay the execution of the script until after the document is fully loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With