The Complete Web Performance Guide: From Core Web Vitals to a Shippable Checklist

Performance Drives Both Conversion and Ranking

Faster pages convert better, and the direction holds across industries; Google also counts Core Web Vitals as a ranking signal. Optimise in order of payoff: shrink the first-screen critical path first, worry about compression algorithms later.

This guide covers the full chain — what blocks first paint, how to cut asset weight, and how caching and protocols fit. For measurement models (lab versus field, P75, per-metric causes) see Core Web Vitals explained.

The Critical Rendering Path: What Holds Up First Paint

First paint roughly runs: parse HTML → build the DOM → load and parse CSS → build the CSSOM → execute JS → build the render tree → lay out → paint.

Only two resource types block: CSS and synchronous JS. CSS blocks rendering; synchronous JS blocks HTML parsing itself, which is more expensive because it delays discovery of everything after it.

CSS Must Block — So Minimise Its Scope

CSS blocks for good reason: without it you get a flash of unstyled content. Do not remove the blocking; shrink it to above-the-fold:

<!-- Critical CSS inlined -->
<style>/* above-the-fold styles */</style>

<!-- Non-critical CSS, non-blocking -->
<link rel="preload" href="/full.css" as="style" onload="this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="/full.css"></noscript>

Free JavaScript with defer / async

Attribute When it executes Order guaranteed Use for
None (sync) As soon as downloaded; blocks parsing Document order Tiny scripts that must run first
async As soon as downloaded No Fully independent scripts (analytics, ads)
defer After parsing, before DOMContentLoaded Yes Scripts touching the DOM or each other
type="module" Behaves like defer by default Yes Modern modular code

Default to defer. Reserve async for genuinely independent third-party scripts — without ordering, two dependent scripts will fail at random.

Fonts: Non-Blocking and Jump-Free

Web fonts threaten both LCP and CLS, so handle three things together:

<!-- 1. Connect early -->
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

<!-- 2. Load without blocking: media="print" does not block while it does not match,
     then onload switches it back to all -->
<link rel="preload" as="style" href="https://fonts.googleapis.com/css2?family=Inter&display=swap">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter&display=swap"
      media="print" onload="this.media='all'">
/* 3. Match the fallback's metrics to the target font to avoid reflow on swap */
@font-face {
  font-family: 'Inter-fallback';
  src: local('Arial');
  size-adjust: 107%;
}

display=swap keeps text readable immediately; the media="print" trick removes blocking, not the font file's own weight — subset it if it is large.

Images: The Single Biggest Win

Images routinely make up over half a page's bytes and are the easiest place to gain. Three levers, in order of payoff.

1. Dimensions (biggest payoff, most often ignored)

A 3000px image in a 300px container wastes bandwidth and also decode and compositing time on slow devices. Let the browser choose with srcset + sizes:

<img src="photo-800.jpg"
     srcset="photo-400.jpg 400w, photo-800.jpg 800w, photo-1600.jpg 1600w"
     sizes="(max-width: 600px) 100vw, 800px"
     width="800" height="600"
     alt="Description"
     loading="lazy" decoding="async">

The browser picks a candidate from the layout width declared in sizes and the device pixel ratio; it never downloads large and scales down. A sizes value that disagrees with the real CSS width picks the wrong candidate, so change them together.

2. Format (second biggest)

Format Versus JPEG Alpha Animation Browser support Use for
AVIF ~50% smaller Yes Yes Newer (Safari 16+) Preferred; slow to encode, so batch offline
WebP 25–35% smaller Yes Yes Broad The safe default
JPEG Baseline No No Universal Photo fallback
PNG Larger Yes No Universal Lossless or transparency where SVG does not fit
SVG Tiny Yes Possible Universal Icons, logos, simple graphics

Let the browser pick by type inside <picture> rather than sniffing in JavaScript — sniffing waits for script execution, which pushes image discovery behind JS:

<picture>
  <source type="image/avif" srcset="photo.avif">
  <source type="image/webp" srcset="photo.webp">
  <img src="photo.jpg" width="800" height="600" alt="Description">
</picture>

For full characteristics and the alpha and animation edge cases, see the image formats cheat sheet.

3. Loading Timing

  • Never lazy-load the first-screen image: loading="lazy" waits for layout before requesting, which delays LCP; use fetchpriority="high" and preload instead;
  • Everything below the fold gets loading="lazy";
  • Add decoding="async" so decoding stays off the main thread.
<!-- LCP element: load with priority -->
<img src="hero.jpg" fetchpriority="high" decoding="async" width="1200" height="600" alt="Hero">

<!-- Below the fold: lazy -->
<img src="item.jpg" loading="lazy" decoding="async" width="300" height="200" alt="List item">

To control first-screen image weight, our image compressor runs entirely in your browser.

JavaScript and CSS Size

JavaScript: Split Before You Compress

Technique What it does Priority
Route-level splitting Ship only the code this page needs Highest
Drop unused dependencies Use a bundle analyser to spot outsized packages High
Dynamic import Load heavy features (editors, charts, PDF) on demand High
Tree shaking Requires ESM and a correct sideEffects declaration Medium
Minification Most of its benefit is already eaten by gzip/brotli Low

The line to watch: be wary once compressed first-screen JS passes 300 KB. Check whether an editor, charting library or PDF parser got bundled into the first screen — that code costs parse and execution time, which minification cannot remove.

CSS: Deleting Beats Compressing

  • Remove unused CSS (Tailwind, PurgeCSS and similar)
  • Inline critical CSS (see the critical rendering path above)
  • Compress last: CSS minification usually saves only a few KB

The Network Layer: Caching and Protocols

Caching Strategy

Resource type Recommended policy Example
Hashed static assets Long-lived, immutable Cache-Control: max-age=31536000, immutable
HTML documents Revalidate every time Cache-Control: no-cache plus ETag
API responses Short, or business-specific Cache-Control: private, max-age=60
Images and media Medium plus revalidation Cache-Control: public, max-age=86400, must-revalidate

The core pattern: put a content hash in the filename (app.a1b2c3.js), so changing content changes the URL and a one-year cache is safe; never hard-cache HTML, so a release takes effect immediately.

Two things people miss: compressed responses need Vary: Accept-Encoding, or a cache may hand a gzipped body to a client that cannot decode it; must-revalidate on media forces a validation request every time, so use immutable when the bytes truly never change.

Compression and Protocols

  • Prefer Brotli, fall back to gzip — Brotli is typically another 15–20% smaller
  • HTTP/2 or HTTP/3 — once multiplexing exists, domain sharding is actively harmful: each extra host costs another DNS lookup and TLS handshake
  • A CDN — push static assets to edge nodes near your users
  • Connect early — preconnect for critical third-party origins, dns-prefetch for secondary ones

Check caching and compression response headers entry by entry against the HTTP headers cheat sheet.

Metrics: Just the Pass/Fail Model

Judge by CrUX at P75: LCP ≤ 2.5 s, INP ≤ 200 ms, CLS ≤ 0.1, all three passing together. A single Lighthouse run is for diagnosis, not for the verdict. Lab versus field, ranked causes per metric and measurement commands are in Core Web Vitals explained.

Pre-Launch Checklist

  • [ ] Every <img> / <video> / <iframe> has width and height (or aspect-ratio)
  • [ ] The LCP element is not lazy-loaded and carries fetchpriority="high"
  • [ ] All below-the-fold images use loading="lazy"
  • [ ] Images served as AVIF/WebP with a JPEG/PNG fallback
  • [ ] Critical CSS inlined, non-critical CSS loaded without blocking
  • [ ] JS defaults to defer; third-party scripts async or deferred
  • [ ] Fonts load without blocking with display=swap, fallbacks metric-matched
  • [ ] Static assets hashed with max-age=31536000, immutable
  • [ ] Brotli or gzip enabled, with Vary: Accept-Encoding on compressed responses
  • [ ] Compressed first-screen JS kept under 300 KB
  • [ ] No long task over 50 ms holding the main thread

Reproducible Results

Establish a reproducible baseline before optimising — "it feels faster" is not a conclusion; milliseconds are:

curl -s -o /dev/null -w 'TTFB: %{time_starttransfer}s  total: %{time_total}s\n' \
  http://127.0.0.1:3100/
# → TTFB: 0.0xxs  total: 0.0xxs (local SSR first byte is typically tens of milliseconds)

time_starttransfer is TTFB — server processing plus one network round trip. Record it before and after each change and every optimisation becomes auditable data. For browser-side LCP/CLS/INP run Lighthouse and take the median of several runs per URL.

Frequently Asked Questions

What do the three Core Web Vitals measure, and what are the thresholds?

LCP (Largest Contentful Paint) measures loading speed, with a good score of 2.5 seconds or less. INP (Interaction to Next Paint) measures responsiveness, with a good score of 200 ms or less — it officially replaced FID in March 2024. CLS (Cumulative Layout Shift) measures visual stability, with a good score of 0.1 or less. All three are evaluated at the 75th percentile, meaning three quarters of real user visits must pass, and all three must pass together. These come from real user data (CrUX), not a Lighthouse lab run.

My CLS won't come down. What are the most common causes?

In order of frequency: 1. images, videos, or iframes without width and height — the browser cannot reserve space, so content gets pushed down once they load; this is the number one cause. 2. Ads, embeds, or lazy-loaded blocks injected after render. 3. Web fonts causing text reflow (FOUT/FOIT). 4. Banners or notification bars inserted above existing content. 5. Animations using layout-triggering properties such as top, left, or width. Fix in this order: give every media element explicit dimensions or aspect-ratio, then reserve space for dynamically injected regions, then handle fonts with font-display: optional or preloading.

Should I use WebP or AVIF for images?

Prefer AVIF, fall back to WebP, then to JPEG/PNG. At equivalent visual quality, AVIF is typically around 50% smaller than JPEG and WebP 25–35% smaller. The tradeoff for AVIF is slower encoding — fine for offline batch processing, not for real-time generation — and slightly later browser support (Safari 16+). Do it properly with <picture> and let the browser choose rather than sniffing with JavaScript: &lt;source type=&quot;image/avif&quot;&gt; → &lt;source type=&quot;image/webp&quot;&gt; → &lt;img&gt; as the fallback. Do not ignore dimensions: dropping a 3000px image into a 300px container wastes everything the format gained you, so a responsive srcset usually delivers a bigger win than switching formats.

My Lighthouse score is high, so why does CrUX still show a failure?

Because they measure different things. Lighthouse is lab data: one run under fixed network and device conditions, stable and reproducible, good for diagnosing problems. CrUX is field data: it reflects real devices, real networks, and real interaction paths, and it is what Google uses for ranking. Typical sources of the gap: a large share of real users on low-to-mid-range Android phones (3–5x slower CPU), high mobile network latency, and the fact that real users scroll and click, triggering lazy loading and interactions Lighthouse never performs. Judge pass/fail on CrUX alone, and use Lighthouse to find out why.

← Back to Blog