Web - Timeline of a page load (Page Speed|Page Latency)

About

Page load is the latency performance metrics that cumulates:

  • TCP latency (ie how fast, HTTP will be delivered)
  • and HTML latency (ie how fast a page will be rendered)

Processing

HTML code is loaded by the browser in the order it appears in the file. Ie the code on the page (ie HTML, CSS, Javascript, …) is processed top down

For instance, let's say you have the following script inlined in your HTML page.

<script>alert('Blocking alert');</script>
<img src="/_media/lenna.png" width="200px"/>

When the page is loaded, the browser will execute the alert, the alert window will pop up and the page will stop loading until the alert window is closed. Ie in this case, you will not see the image

Load is not a single moment in time — it’s an experience that no one metric can fully capture. There are multiple moments during the load experience that can affect whether a user perceives it as “fast” or “slow”.

Timeline / State

The main page state of the loading process are available in the readyState property

There is no rendering event that notify of the first rendering but as the rendering complete after the first two animation frames rendering of the loaded event, you can simulate the event with the requestAnimationFrame web api function.

Example:

function renderingCompleted() {
        console.log("Rendering completed")
}
function renderingStarted() {
    console.log("Rendering started");
    requestAnimationFrame(renderingCompleted);
}
window.addEventListener("load", function () {
    requestAnimationFrame(renderingStarted);
});
  • Output:

_

Example

Webpack _

API

Statistics

Your web analytics provider should provide you with them.

Example for Google Analytics

_

Control

Script

If JavaScript through the script element is placed before the body (without the HTML - Defer attribute attribute), it will therefore be loaded first and if it is supposed to affect the HTML in the body, it might not work, as the JavaScript would be loaded before the HTML it is supposed to work on.

Scripts in HTML have “run-to-completion” semantics, meaning that the browser will generally run the script uninterrupted before doing anything else (without the HTML - Defer attribute attribute), such as:

Slow page

Probability of bounce by page latency.

(Slow pages lose user)

_

Icon / Progress while loading

The icon while loading is known as a Throbber.

User perception

  • 100 ms: user perceives as instantaneous
  • 1s: is about the upper limit of human flow of though. User loses the feeling direct feedback
  • 10s: Upper limit of attention. Feedback is important and the chance of context switch is high.

Record

To record a page load, you would use a headless browser

Utility

Documentation / Reference


Powered by ComboStrap