JavaScript DOMContentLoaded event case study

JavaScript DOMContentLoaded event case study

DOMContentLoaded Event

Literally, it fires after the DOM is loaded.

Very similar to the window.onload event, but with some differences:

  1. The DOMContentLoaded event is triggered after the document is fully loaded and parsed;
  2. The window.onload event not only completes the loading and parsing of the document, but also completes the loading of related resources, such as images and CSS files.

The next question is when the DOM is loaded. This starts with browser rendering. The process of browser displaying a web page can be described as follows:

1. Request an HTML document, and then request more img, css and other resource files based on the document;

2. Parse the document to get two things, DOM tree and CSS tree;

3. Generate render tree based on the above two trees;

4. Perform layout according to the render tree and draw related elements in it.

Taking webkit as an example, its rendering process is as follows:

DOMContentLoaded event triggers when:

After DOM and before RENDERtree.

JavaScript loading and execution will delay the triggering of the DOMContentLoaded event.

JavaScript has to wait for CSS rendering to complete before loading and executing, because the browser cannot determine whether JavaScript needs DOM element information.

To ensure that JavaScript has the latest information, the CSS is loaded and rendered first.

Reference Documents:

http://www.softwhy.com/article-9783-1.html

https://www.cnblogs.com/CandyManPing/p/6635008.html

https://www.cnblogs.com/caizhenbo/p/6679478.html

This is the end of this article about the detailed case of JavaScript DOMContentLoaded event. For more relevant JavaScript DOMContentLoaded event content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JavaScript Learning Summary (I) ECMAScript, BOM, DOM (Core, Browser Object Model and Document Object Model)
  • Detailed explanation of BOM and DOM in JavaScript
  • Java parsing xml file and json conversion method (DOM4j parsing)
  • Let’s talk in detail about how JavaScript affects DOM tree construction
  • Does contains in javascript contain function implementation code (extended characters, arrays, DOM)?
  • Document Object Model (DOM) in JavaScript

<<:  Two methods to implement MySQL group counting and range aggregation

>>:  How to expand Linux swap memory

Recommend

Detailed explanation of Linux inotify real-time backup implementation method

Real-time replication is the most important way t...

Four ways to combine CSS and HTML

(1) Each HTML tag has an attribute style, which c...

React gets input value and submits 2 methods examples

Method 1: Use the target event attribute of the E...

How to enable slow query log in MySQL

1.1 Introduction By enabling the slow query log, ...

Display mode of elements in CSS

In CSS, element tags are divided into two categor...

Analyzing the troublesome Aborted warning in MySQL through case studies

This article mainly introduces the relevant conte...

Introduction to the B-Tree Insertion Process

In the previous article https://www.jb51.net/arti...

Implementing simple tabs with js

Tab selection cards are used very frequently on r...

Zabbix monitoring docker application configuration

The application of containers is becoming more an...

How to start multiple MySQL instances in CentOS 7.0 (mysql-5.7.21)

Configuration Instructions Linux system: CentOS-7...

HTML checkbox Click the description text to select/uncheck the state

In web development, since the checkbox is small an...

How to build a drag and drop plugin using vue custom directives

We all know the drag-and-drop feature of HTML5, w...