Skip to content
syntaqx

Frontend, chapter 02 of 09

Web Performance

Core Web Vitals targets measured from real users, performance budgets enforced in CI, and the handful of habits that keep pages fast: less JavaScript first.

4 min readUpdated

Speed is a feature people notice only when it's missing, and it shows up directly in revenue: in a Deloitte study of mobile sites, a tenth of a second faster across the journey lifted retail conversions by 8.4%.

It's also one of the few features that degrades on its own. Every dependency, image and script is added for a good reason, and each makes the page a little slower; nobody decides to make the site slow. So performance is held with budgets that fail the build, not fixed in a big project every couple of years.

Targets: Core Web Vitals#

I use the Core Web Vitals as targets because they measure what users feel (does the main content show up, does the page respond, does it stop jumping around) rather than what's convenient, like total bytes. Each is judged at the 75th percentile of real page loads, separately for mobile and desktop: the median hides the slower devices where people give up, and the 99th is dominated by outliers you can't fix.

Metric Measures Good
Largest Contentful Paint (LCP) Loading: when the main content appears 2.5 s or less
Interaction to Next Paint (INP) Responsiveness: how fast the page reacts to input 200 ms or less
Cumulative Layout Shift (CLS) Visual stability: how much content jumps around 0.1 or less

Past the good threshold, each metric has a poor one: LCP over 4 seconds, INP over 500 ms and CLS over 0.25, with "needs improvement" in between (Defining the Core Web Vitals thresholds). The LCP target is also a budget to split: web.dev suggests roughly 40% of it for the server's first byte, 40% for loading the LCP resource, and under 10% each for the delays before the load and before the render (Optimize LCP).

NOTES: (UNLESS OTHERWISE SPECIFIED) 1 GOOD LCP IS 2.5 S OR LESS; THE SPLIT IS PUBLISHED GUIDANCE ON WHERE THE TIME GOES, NOT A RULE. 2 EACH METRIC IS JUDGED AT THE 75TH PERCENTILE OF REAL PAGE LOADS, FOR MOBILE AND DESKTOP SEPARATELY. 3 ABOUT 40% EACH FOR TTFB AND LOAD DURATION, UNDER 10% EACH FOR THE DELAYS, DRAWN AT THEIR CEILING. VALUES IN S UNLESS MARKED. THE DRAWING CARRIES CODES; VALUES AND FORMULAS ARE IN THE TABLE. TIME TO FIRST BYTE LOAD DURATION LOAD DELAY RENDER DELAY T1 T2 T3 T4 3 L1 1 PLAN VIEW · LCP BUDGET BY SUBPART SCALE 1 S = 240 PX · TIMELINE LCP G1 P1 GOOD NEEDS IMPROVEMENT POOR INP G2 P2 CLS G3 P3 PLAN VIEW · THRESHOLDS AT THE 75TH PERCENTILE LCP 1 S = 108 PX · INP 100 MS = 72 PX · CLS 0.1 = 108 PX 2 VARIABLES · PUBLISHED LCP GUIDANCE AND THRESHOLDS CODE VARIABLE VALUE L1 LCP, good at the 75th percentile 2.50 T1 time to first byte ≈ 0.40 × L1 = 1.00 T2 resource load delay ≤ 0.10 × L1 = 0.25 T3 resource load duration ≈ 0.40 × L1 = 1.00 T4 element render delay ≤ 0.10 × L1 = 0.25 C1 chain, closes on L1 T1 + T2 + T3 + T4 = 2.50 G1 / P1 LCP good up to / poor over 2.5 s / 4.0 s G2 / P2 INP good up to / poor over 200 ms / 500 ms G3 / P3 CLS good up to / poor over 0.1 / 0.25 Dimensional drawing of a Core Web Vitals budget. The 2.5-second good LCP threshold is split into time to first byte at about 40 percent, 1.00 s, a resource load delay of at most 0.25 s, a load duration of about 1.00 s, and a render delay of at most 0.25 s, summing to 2.50 s. A second view draws the good, needs improvement and poor bands for each metric at the 75th percentile: LCP at 2.5 and 4.0 s, INP at 200 and 500 ms, CLS at 0.1 and 0.25.
The LCP target is a budget with four parts; a slow server spends the image's share before the image is even requested.

INP replaced First Input Delay as a Core Web Vital in March 2024. It measures every interaction, not just the first, which makes heavy JavaScript much harder to hide.

Core Web Vitals also feed search ranking, though behind relevance; how much they count is in SEO.

Measure Real Users#

  • Field data decides. Real-user monitoring (RUM) and the Chrome UX Report show what people actually experience, on their devices and networks. Collecting it yourself is Real-User Monitoring.
  • Lab data explains. Lighthouse and DevTools traces find why a number is bad and check a fix; they don't declare victory. A fast laptop on office Wi-Fi is not your median user.
  • Watch the 75th percentile, not the average. An average blends a fast majority with a slow minority into a number that describes nobody.

Budgets in CI#

A budget turns "keep it fast" into a check that fails:

  • JavaScript size per route, compressed. The first budget to set, because it's the most common regression.
  • Lab metrics on key pages with Lighthouse CI, asserting LCP, CLS and total blocking time stay under thresholds.
  • A new dependency has to fit the budget, or something else gets removed. See Dependencies & Upgrades.

Set budgets from where you are today, then tighten them. A budget nobody can meet gets ignored.

Ship Less JavaScript#

JavaScript is the most expensive byte on the page: downloaded, parsed, compiled and executed on a slow phone's main thread, which is exactly what INP measures.

  • Render on the server or at build time, and send HTML. Static and server rendering get content on screen without waiting for a bundle.
  • Hydrate only what's interactive. A page of text doesn't need a client-side app.
  • Split by route, and load heavy components (editors, charts, maps) when they're needed.
  • Question every dependency's size before adding it. A date library for one format is rarely worth it.

Images#

  • Modern formats (AVIF, WebP) with explicit width and height so the browser reserves space and CLS stays at zero.
  • Responsive sizes with srcset and sizes, so phones don't download desktop images.
  • Lazy-load below the fold, and never the LCP image. The LCP image gets fetchpriority="high" instead (Optimize LCP).

Fonts#

  • Self-host and subset to the characters you use.
  • font-display: swap or optional, so text renders immediately in a fallback instead of staying invisible.
  • Preload only the one or two fonts above the fold. Preloading everything competes with the content that matters (font best practices).
  • Match fallback metrics to the web font, so the swap doesn't shift the layout.

Caching#

Static assets get content-hashed filenames and Cache-Control: public, max-age=31536000, immutable, so repeat visits load them from the browser cache. HTML and API responses revalidate. See Caching & Conditional Requests. Text assets are precompressed at build time at the maximum level, as in HTTP Compression.

Third-Party Scripts#

Every tag, widget and pixel runs on your users' devices and counts against your Core Web Vitals. Each needs an owner and a reason, loads after the content, and goes when nobody can say what it's for.

References#

Reference

In practice