admin管理员组文章数量:1400161
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:
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:
Share Improve this question asked Mar 10, 2014 at 7:15 hh54188hh54188 15.7k35 gold badges116 silver badges192 bronze badges 1-
AFAIK, javascript never runs in parallel with rendering the page. What you achieve is not blocking the parser, or the load of other resources. That's because async scripts can't use
document.write
. I'm curious for more plete answers, though. Nice question! – Renato Zannon Commented Mar 10, 2014 at 7:17
1 Answer
Reset to default 9The 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.
本文标签: javascriptscript element with async attribute still block browser renderStack Overflow
版权声明:本文标题:javascript - script element with async attribute still block browser render? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744208468a2595305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论