Tech Interview RoomStudy guides

Browser & Performance

What are Core Web Vitals and how do you improve each?

Intermediate · 2 min read · Lesson 3 of 8 in Browser & Performance

Core Web Vitals are Google's user-centred metrics, measured on real users (field data from the Chrome UX Report) at the 75th percentile, and used as a search ranking signal.

LCP: Largest Contentful Paint (loading). Good: ≤ 2.5 s

When the largest image or text block in the viewport is rendered.

  • Serve the HTML fast (CDN, caching, server rendering); reduce time to first byte.
  • Make the LCP image discoverable in the HTML (not lazy-loaded, not injected by JavaScript); add fetchpriority="high" and preload if needed.
  • Compress images (AVIF/WebP, correct size), remove render-blocking CSS/JS, preload fonts.

INP: Interaction to Next Paint (responsiveness). Good: ≤ 200 ms

The delay from a click, tap or key press until the next frame paints, taken from (nearly) the worst interaction of the visit. It replaced FID in 2024.

  • Break up long tasks (over 50 ms); yield to the main thread (scheduler.yield(), setTimeout).
  • Do less JavaScript per interaction: show feedback first, defer non-essential work, use transitions in React.
  • Avoid large re-renders and layout thrashing; move heavy work to Web Workers.
  • Reduce third-party scripts.

CLS: Cumulative Layout Shift (visual stability). Good: ≤ 0.1

How much visible content moves unexpectedly.

  • Always set width/height or aspect-ratio on images, videos, iframes and ads.
  • Reserve space for banners and late content; do not insert content above existing content.
  • Use font-display: optional or size-adjusted fallback fonts to avoid text jumps.
  • Animate with transform instead of properties that move layout.

Example

html
<img src="/hero.avif" width="1200" height="600" fetchpriority="high" alt="Product hero" />
<img src="/footer-map.webp" width="600" height="300" loading="lazy" decoding="async" alt="Map" />
js
import { onLCP, onINP, onCLS } from 'web-vitals';

function send(metric) {
  navigator.sendBeacon('/analytics', JSON.stringify({ name: metric.name, value: metric.value, id: metric.id }));
}
onLCP(send);
onINP(send);
onCLS(send);

Follow-up questions interviewers ask

Try answering each one before you open it.

Lab data vs field data?

Lab tools (Lighthouse, WebPageTest) run one load on a simulated device: reproducible and good for debugging, but they cannot measure INP from real interactions. Field data (CrUX, your own RUM with the web-vitals library) reflects real devices and networks. Optimise using lab data, and judge success with field data.