Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 37 ยท Performance and Lighthouse

PWA Performance Basics

Make a PWA feel instant: Core Web Vitals (LCP, INP, CLS), the app shell model, what service workers help or hurt, performance budgets and measuring in the field.

A PWA that installs, works offline and sends notifications but takes six seconds to show something will still lose users. Performance is part of what "progressive web app" means: the app should be fast on the first visit, on a cheap phone, on a poor network. A service worker helps a great deal on repeat visits, but the first visit and the code you ship decide how good the experience can be.

This lesson explains the metrics that matter, how the app shell model uses the service worker, what a service worker can slow down, and how to set a budget and measure real users. The next two lessons cover Lighthouse audits and loading techniques.

The metrics that matter

Google's Core Web Vitals are three user-centered measurements that also influence search ranking:

Metric Measures Good Poor
LCP (Largest Contentful Paint) When the main content appears up to 2.5 s over 4 s
INP (Interaction to Next Paint) How quickly the page responds to taps and clicks up to 200 ms over 500 ms
CLS (Cumulative Layout Shift) How much the layout jumps while loading up to 0.1 over 0.25

Other numbers you will see: TTFB (time to first byte, server and network speed), FCP (first contentful paint) and TBT (total blocking time, a lab stand-in for INP). The "good" thresholds apply to the 75th percentile of real visits, so one fast laptop test proves little.

JS Rate your vitals

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The app shell model

An app shell is the minimal HTML, CSS and JavaScript that draws the user interface frame: header, navigation, empty content area. You precache it in the service worker, so on repeat visits it loads straight from disk, then the app fills in content from the network or from local data.

flowchart TD
  A["First visit"] --> B["Server HTML + shell assets"]
  B --> C["Service worker installs and precaches the shell"]
  D["Next visit"] --> E["Shell from cache: instant frame"]
  E --> F["Content from network or IndexedDB"]

The shell makes the second visit feel native. The first visit still needs to be lean.

Caution: a shell that is only an empty box makes the metrics worse, not better, because LCP happens when the real content arrives. For content sites, server-rendered HTML for the main content plus a cached shell often beats a client-rendered single-page app. Many successful PWAs are traditional multi-page sites with a service worker added on top.

What a service worker helps, and what it hurts

Helps:

  • Repeat visits: cached assets skip the network entirely.
  • Offline and flaky networks: the app still loads.
  • Predictable speed: no round trip for versioned static files.

Can hurt:

  • Startup cost. A sleeping worker must start before it can answer a request, adding tens of milliseconds. Enable navigation preload for network-first pages.
  • Heavy install work. Precaching 30 MB of assets competes with the page for bandwidth on the first visit. Precache only the shell and critical routes; cache the rest lazily.
  • Stale content. A cache-first strategy for HTML can show last week's page. Choose the strategy per resource type (see caching strategies).
  • Slow handler code. Expensive work inside fetch blocks every request.

Set a performance budget

A budget is a number you refuse to exceed, checked automatically. Typical budgets:

  • JavaScript: under 170 KB compressed for the initial route on mobile.
  • Total transfer for the first view: under 1 MB.
  • LCP under 2.5 s on a mid-range phone and slow 4G.
  • No layout shifts from images without dimensions.
JS A tiny budget checker

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Run such a check in continuous integration (Lighthouse CI and bundler plugins can enforce budgets), so regressions are caught before users feel them.

Measure real users

Lab tools run in a controlled environment. Field data comes from real devices. The web-vitals library from Google reports all three metrics in a few lines:

JavaScript
// read-only: runs in the page
import { onLCP, onINP, onCLS } from "web-vitals";

function send(metric) {
  navigator.sendBeacon("/analytics/vitals", JSON.stringify({
    name: metric.name,
    value: metric.value,
    id: metric.id,
    page: location.pathname,
  }));
}
onLCP(send); onINP(send); onCLS(send);

sendBeacon survives the page closing, which is when several metrics finalize. Chrome also publishes anonymous field data for public sites in the Chrome UX Report, visible in PageSpeed Insights.

Under the hood these libraries use PerformanceObserver:

JavaScript
new PerformanceObserver((list) => {
  const entries = list.getEntries();
  console.log("LCP candidate:", entries.at(-1).startTime);
}).observe({ type: "largest-contentful-paint", buffered: true });

Quick wins that usually matter most

  1. Serve compressed text (Brotli or gzip) and use HTTP caching headers with hashed file names.
  2. Give images width and height (or aspect-ratio) to avoid layout shift, and use loading="lazy" below the fold.
  3. Use modern formats (AVIF, WebP) and responsive srcset.
  4. Load fonts with font-display: swap and preload the one you need first.
  5. Split JavaScript by route; do not ship the admin panel to every visitor.
  6. Break up long tasks (over 50 ms) so taps respond quickly.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which metric measures how stable the layout is during loading?

    Cumulative Layout Shift sums unexpected layout movement.
  2. 2. Why can an app shell that is only an empty frame still give a poor LCP?

    LCP records when the main content is painted. An empty frame defers that until the content loads.
  3. 3. A service worker precaches 30 MB on install. What is the risk?

    Heavy install work slows the first view, which is the one you cannot cache.
  4. 4. Why prefer field data to a single lab run?

    A fast test machine can hide the experience of typical visitors.

Summary

  • Watch LCP, INP and CLS; judge them at the 75th percentile of real visits.
  • An app shell speeds repeat visits but does not replace fast first-load content.
  • Service workers add startup cost and staleness risks as well as speed; precache little and choose strategies per resource.
  • Set budgets and enforce them in CI; measure real users with web-vitals.

Next: Lighthouse Audits