When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps. These include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering.
When a web page is loaded, the browser first reads the HTML text and constructs DOM Tree from it. Then it processes the CSS whether that is inline, embedded, or external CSS and constructs the CSSOM Tree from it. After these trees are constructed, then it constructs the Render-Tree from it.
What you are talking about is the Critical Rendering Path.
The point 1., 3. and 4. can be resumed as such:
Here is a break down of what happens behind the scene.
1. Constructing the DOM object.
The first step is creating the DOM. Indeed what you receive from the network are bytes and the browser use the so called DOM tree. Therefor it needs to convert those bytes into the DOM tree.
You can check the developer tool to see how much time it takes.
Here we can see it took 4.938ms.
When this process is finished the browser will have the full content of the page, but to be able to render the browser has to wait for the CSS Object Model, also known as CSSOM event, which will tell the browser how the elements should look like when rendered.
2. Handling the CSS
For the css it's the same as above, the browser needs to convert those file into the CSSOM:
The css is also a tree structure. Indeed if you put a font-size to the parent element then the children will inherit it.
That's called recalculate style in the developer tool
CSS is one of the most important elements of the critical rendering path, because the browser blocks page rendering until it receives and processes all the css files in your page, CSS is render blocking
3. Render tree
CSSOM AND DOM are combined for display.
4. Layout
Everything has to be calculated in pixels. So when you say an element has a width of 50%, the browser behind the scene transform that in pixels:
Every time an update to the render tree is made, or the size of the viewport changes, the browser has to run layout again.
5.Paint
The step is converting all this into pixels on screen. This is the paint step.
Javascript
For the JavaScript lifecycle you can find info here.
The gist of it is that the event you most likely care about is DOMContentLoaded
. This is when the DOM is ready.
When the browser initially loads HTML and comes across a
<script>...</script>
in the text, it can’t continue building DOM. It must execute the script right now. So DOM Content Loaded may only happen after all such scripts are executed.External scripts (with src) also put DOM building to pause while the script is loading and executing. So DOM Content Loaded waits for external scripts as well.
The only exception are external scripts with async and defer attributes. They tell the browser to continue processing without waiting for the scripts. So the user can see the page before scripts finish loading, good for performance.
Beside that, where is JavaScript in all this ?
Well it's being executed between the repaints. However it is blocking. The browser will wait for JavaScript to be done before repainting the page. That means that if you want your page to have good response (lots of fps), then the JS has to be relatively inexpensive.
Cookies
When receiving an HTTP request, a server can send a Set-Cookie header with the response. The cookie is usually stored by the browser and, afterwards, the cookie value is sent along with every request made to the same server as the content of a Cookie HTTP header. Additionally, an expiration delay can be specified as well as restrictions to a specific domain and path, limiting how long and to which site the cookie is sent to.
For the networking stuff, this is beyond the scope of browser lifecycle, which your question is about. This is also something I'm not well versed in but you can read about TCP here . What you might be interested in is the handshake.
Sources:
Critical rendering path
critical rendering path
Cookies
js lifecycle
tcp
http
You can find many explanations on this topic, but I guess following is the easiest explanation to understand how browser(s) renders a web page.
Source
I'd like to suggest the following for anyone who would like to watch what happens, it's a cheap answer but it might be useful to explain how the browser retrieves it's cascade of files to construct the contents of a URL (in this case an html).
Play with the settings. You should also look at the timeline created in the Performance tab
It may be useful here to throttle back the performance, so you can watch it in real time (slow) if that's something you want to demonstrate.
The important thing is (using an HTML page as an example), the order of rendering/applying css/running javascript, depends on where it appears in the DOM. It's possible to execute a script at any point after it's loaded, subject to the required resources being available. Css could be part of the HTML document (inline) or it might be coming from a very busy server and take 10-20 seconds before it can be applied. Hope this is of some help -R
Some other useful resources:
Firefox 3D tilt plugin help visualise webpages and how they are rendering content in different layers.
Chrome's performance tab a good visualisation of what happens during a page load and how the dom tree is constructed. It helps in identifying the bottlenecks in the render process.
You can see a lot of backend functionality of your browser like the cached HTML content, cached images, dns cache, open ports etc. by opening chrome://net-internals/.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With