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

Example code for implementing background blur effect with CSS

Is it the effect below? If so, please continue re...

Solution to 1045 error in mysql database

How to solve the problem of 1045 when the local d...

JS implements the sample code of decimal conversion to hexadecimal

Preface When we write code, we occasionally encou...

Solution to MySQLSyntaxErrorException when connecting to MySQL using bitronix

Solution to MySQLSyntaxErrorException when connec...

How to use ElementUI pagination component Pagination in Vue

The use of ElementUI paging component Pagination ...

Analysis of the principle of Rabbitmq heartbea heartbeat detection mechanism

Preface When using RabbitMQ, if there is no traff...

Pure CSS to achieve automatic rotation effect of carousel banner

Without further ado, let’s get straight to the co...

Linux general java program startup script code example

Although the frequency of starting the shell is v...

Pessimistic locking and optimistic locking in MySQL

In relational databases, pessimistic locking and ...

How to view the IP address of the Docker container

I always thought that Docker had no IP address. I...

Detailed tutorial for installing mysql5.7.21 under Windows system

MySQL Installer provides an easy-to-use, wizard-b...

Detailed installation and uninstallation tutorial for MySQL 8.0.12

1. Installation steps for MySQL 8.0.12 version. 1...

Detailed tutorial on installing mysql on centos 6.9

1. Confirm whether MySQL has been installed. You ...