前端的純技術就是對規范的認知
什么是DOMContentLoaded事件?
首先想到的是查看W3C的HTML5規范,DOMContentLoaded事件在什么時候觸發:
Once the user agent stops parsing the document, the user agent must run the following steps:
1. Set the current document readiness to “interactive” and the insertion point to undefined.
Pop all the nodes off the stack of open elements.
2. If the list of scripts that will execute when the document has finished parsing is not empty, run these substeps:
2.1 Spin the event loop until the first script in the list of scripts that will execute when the document has finished parsing has its “ready to be parser-executed” flag set and the parser's Document has no style sheet that is blocking scripts.
2.2 Execute the first script in the list of scripts that will execute when the document has finished parsing.
2.3 Remove the first script element from the list of scripts that will execute when the document has finished parsing (i.e. shift out the first entry in the list).
2.4 If the list of scripts that will execute when the document has finished parsing is still not empty, repeat these substeps again from substep 1.
3. Queue a task to fire a simple event that bubbles named DOMContentLoaded at the Document.
規范總是那么的晦澀,但至少有一點是可以明確了的,就是在JS(不包括動態插入的JS)執行完之后,才會觸發DOMContentLoaded事件。
接下來看看MDN上有關DOMContentLoaded事件的文檔:
The DOMContentLoaded event is fired when the document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading
Note: Stylesheet loads block script execution, so if you have a<script>after a<link rel="stylesheet" ...>, the page will not finish parsing 主站蜘蛛池模板: 华阴市| 黑河市| 阿巴嘎旗| 固原市| 女性| 获嘉县| 永年县| 独山县| 保靖县| 平凉市| 雅江县| 河池市| 永德县| 新平| 定州市| 洮南市| 广汉市| 建昌县| 沁源县| 孝感市| 七台河市| 绥江县| 尉犁县| 山东省| 邢台县| 阳西县| 清丰县| 民乐县| 安福县| 融水| 舞钢市| 格尔木市| 广东省| 清水河县| 宜州市| 北京市| 霍林郭勒市| SHOW| 灌云县| 阿克苏市| 丹江口市|