![]() |
In this article, you will understand the flow in which the HTML document loads whenever a web client ( Browser ) makes a request. This process involves three important objects, which are:
document loading is the process in which the content from the server is taken to the client and depicted to the users. Loading takes place through a series of events which is explained with an example below. Let’s say you are making a request to an example domain like www.example.com, The following events happen in the loading of the document:
![]() Workflow of Document Loading in 4 Simple Steps
Syntax: <html> Consider the syntax, when the client gets a file containing the code it initially parses the code starting from the <html> tag and simultaneously starts creating the nodes for the tree, then it encounters the stylesheet link with the name style.css, it makes a request to the server for the CSS file and the CSS file gets downloaded and forms a tree especially for the CSS called as CSSOM, then the process continues with the further tags in the HTML file, ultimately it downloads the script.js file and forwards it to the JS engine. Events during the document loading process:Some events in javascript represent the loading of the document with the help of which we can take actions in the script while the document is loading. There are 4 important events in the document lifecycle which can be accessed with Javascript :
Additionally, to know the state of the document, you can refer to the document.readyState property that contains 3 possible values:
The below two examples demonstrate the above-mentioned events Example 1: In this, we will analyze the working of all the above events and the sequence in which they execute. The document makes a call to the bootstrap stylesheet and the script. The Gif output shows the waterfall timeline of the loading using the chrome browser.
Output: Here the output shows the domcontentloaded triggers before the load event. The beforeunload confirms the user and the unload is triggered ultimately and erased instantly as the page reloads when you press ctrl + R. Example 2: In this, we will look at the readyState property. It prints the different values of the document.readyState depending upon the state of the document.
Output: Initially the document is downloaded which is shown with interactive and then it is rendered which is shown as complete. ![]() |
Reffered: https://www.geeksforgeeks.org
JavaScript |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |