-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question]Inconsistent defer script description between doc and brower #2573
Comments
What part of the spec leads you to believe DOMContentLoaded fires before defer scripts? The spec section you quote has nothing to do with DOMContentLoaded. If you look at the portion of the spec that fires DOMContentLoaded, I think you will find the opposite. |
Because I think "when the document has finished parsing" means DOMContentLoaded But follow your reminder,I check the the-end section and it says:
So,you are right,my previous thought is wrong,the defer scripts are executed before(not after) the DOMContentLoaded event. More accurate description: after the current document readiness to "interactive" and before the DOMContentLoaded event.(I look up the pending pr and it also shows that before DOMContentLoaded,we have executed all defer scripts.) But this section is the-end section which means we have parsed the html compeletely,but from the screenshot which I post,when the defer js(i.e. the js.js file) finish loading,it was executed immediately and then of course block the html parse,so I am a little confused,I think at least it should be executed when we parse the html compeletely,right? And from the spec's pic: And from your previous comment:
I think both the pic and "we also would need to defer the evaluation of the above script, perhaps by listening to DOMContentLoaded" are the same meaning with I say above. |
Sorry,I think probally I make a mistake,the test demo is from a friend,so I don't check it very carefully.But now I realize that at the end of the body tag has nothing. It misleads me,and let me consider that after the defer script finishing loading,it is executed immediately though certainly the event log of the timeline in chrome shows that.But that's just because there is no extra parse work need to do when the defer script finish loading. So,I add So,I think the spec describes right. If I am wrong or you have any thought,please let me know,thanks a lot! |
So it looks like you've worked this out by reading the spec, which IMO is pretty clear. Your main misconception is that DOMContentLoaded happens immediately after parsing, but that's not accurate; it happens after executing defer scripts. The picture for Glad we could help! I'll close this now since there doesn't seem to be a spec bug, but I'm happy to continue discussing in the closed thread if there are still things you find unclear. |
Thanks for your feedback :)
Yea,sorry it confuses you,because I previous think the end of the green line represent DOMContentLoaded |
the doc says:
My html is:
js.js is:
But I check the timeline in chrome,I find that the js fired before the
DOMContentLoaded
event.But the spec says "Add the element to the end of the list",so I think it means we should execute the defer js after the
DOMContentLoaded
event.If I am wrong,please let me know,thanks!
The text was updated successfully, but these errors were encountered: