当我描述我的应用时,事件会提高1.5秒,但第一个像素出现的时间要晚得多。这可能意味着该事件仅代表DOM树构造。但是这个教程让我有点困惑了
https://developers.google.com/web/fundamentals/performance/critical-rendering-path/analyzing-crp
答案 0 :(得分:0)
初始HTML文档完全加载并解析后,DOMContentLoaded
事件被触发without waiting for stylesheets, images, and subframes to finish loading
。
答案 1 :(得分:-1)
我遇到了同样的问题,所以我读了你提供的谷歌开发者的文章。但是,我得出了一个不同的结论,即当dom树准备好而不等待cssom和渲染树时,它意味着DOMContentLoaded事件触发。 这篇文章的内容是:
*An asynchronous script has several advantages:
The script is no longer parser blocking and is not part of the critical rendering path.
Because there are no other critical scripts, the CSS doesn't need to block the domContentLoaded event.
The sooner the domContentLoaded event fires, the sooner other application logic can begin executing.*
这意味着如果脚本不能通过set" async"来停止domtree解析,那么domcontentloaded event甚至不会等待css加载或解析为cssom。