Measure First — Performance

Measure the Polindes queue page on villagers' phones before changing it: lab, field data, INP. 14 levels, played right in the browser with nothing to install.

What you learn in this game

Load time is the time from opening a link until the page is ready to use. The longer it is, the more visitors leave before they see anything. Developers usually try their page on a fast laptop with good Wi-Fi. Many users open the web on a cheap phone with a signal that comes and goes. Chrome DevTools can imitate both: a slowed CPU (CPU throttling) and a slowed network (network throttling).

Lab data is measured in a controlled simulation: one device, one simulated network, results you can repeat. Lighthouse is an example. Field data is collected from real users, each with their own phone, network and habits. CrUX is an example, or the report you send yourself from a page with PerformanceObserver or the web-vitals library (called RUM, real user monitoring). The two do not contradict each other. The lab is for finding causes, the field is for judging what users experience.

The browser has a performance object for measuring your own code. performance.mark(name) records one point in time. performance.measure(name, start, end) records the gap between two marks, and getEntriesByName(name) returns its entry with a duration in milliseconds. These marks and measures also show in Chrome's Performance panel, on the Timings track.

performance.getEntriesByType('resource') gives one entry for every file the page downloads: CSS, JavaScript, images, data. name is the file's address. duration is the milliseconds from the request being sent until the last byte arrives. transferSize is the bytes that came over the network: 0 when the file came from the cache, or when a file from another site does not allow its numbers to be read. renderBlockingStatus tells whether the file held the first render.

A load time is never exactly the same twice: the network, the server and other work on the device all change. One number from one measurement can be good or bad by chance. Repeat the measurement a few times, then sum it up. The median is the middle value once sorted: of 1,900, 2,000 and 4,100, the median is 2,000. The mean is 2,667, pulled by one far number.

PerformanceObserver tells you each time the browser records a new entry of the type you listen to. With buffered: true, entries from before the observer was set up are sent too. There are three Core Web Vitals today: LCP (the largest content on the first screen showing), CLS (how far the layout shifts), and INP (how quickly the page answers an interaction). The web-vitals library is built on these observers.