前端的純技術就是對規范的認知
什么是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| 辽阳市| 崇州市| 大渡口区| 盘锦市| 赤峰市| 霍州市| 广灵县| 璧山县| 沧州市| 息烽县| 邻水| 兴城市| 凭祥市| 昔阳县| 利川市| 曲麻莱县| 楚雄市| 鹿泉市| 明水县| 万州区| 手游| 红安县| 诸城市| 丹寨县| 璧山县| 嘉荫县| 根河市| 正安县| 正镶白旗| 登封市| 海宁市| 额敏县| 遵义市| 鹤山市| 砚山县| 木里| 延庆县|