DEV Community

Kui Luo
Kui Luo

Posted on

How to Measure and Improve Core Web Vitals in Under 30 Minutes

Core Web Vitals directly impact your search rankings and user experience. Google confirmed in 2024 that sites meeting all three thresholds see an average 15-20% boost in organic traffic.

The Three Metrics That Matter

Metric What It Measures Good Needs Work Poor
LCP (Largest Contentful Paint) Loading speed of main content ≤ 2.5s 2.5s - 4.0s > 4.0s
INP (Interaction to Next Paint) Responsiveness to user input ≤ 200ms 200ms - 500ms > 500ms
CLS (Cumulative Layout Shift) Visual stability during load ≤ 0.1 0.1 - 0.25 > 0.25

Note: INP replaced FID as the responsiveness metric in March 2024.

Step 1: Get Your Baseline Numbers (5 minutes)

Open Chrome DevTools on any page and run a Lighthouse audit. Go to the Performance tab and look for the Core Web Vitals section in the diagnostics panel.

For real-user data, check your search console dashboard. It shows field data aggregated from actual Chrome users over the past 28 days. This is more reliable than synthetic lab tests because it reflects real network conditions and device capabilities.

If you want programmatic access, the Web Vitals JavaScript library collects metrics from real users:

import { onLCP, onINP, onCLS } from 'web-vitals';

onLCP(console.log);
onINP(console.log);
onCLS(console.log);
Enter fullscreen mode Exit fullscreen mode

Send these to your analytics endpoint to track improvements over time.

Step 2: Fix LCP Issues (10 minutes)

The most common LCP bottleneck is a slow hero image. Here are the fixes that move the needle the most:

  • Preload the LCP image. Add a <link rel="preload"> tag in your HTML head for the above-the-fold image. This tells the browser to start downloading it immediately instead of waiting for CSS to discover it.

  • Use modern image formats. Converting PNG/JPEG to WebP or AVIF typically reduces file size by 30-50% with minimal quality loss. Most browsers support WebP now — AVIF support is at 93% and growing.

  • Set explicit width and height on images. Without dimensions, the browser cannot reserve space, causing layout shifts that cascade into slower rendering.

  • Eliminate render-blocking resources. Move critical CSS inline and defer non-critical stylesheets. Scripts should use defer or async attributes.

A practical approach: serve hero images at exactly the display size. Serving a 2400px image for a 600px display slot wastes bandwidth and decode time. Use srcset with multiple resolutions.

Step 3: Reduce INP (8 minutes)

INP measures how quickly your page responds to every click, tap, or key interaction. High INP usually comes from JavaScript blocking the main thread.

  • Break up long tasks. Any task over 50ms is a problem. Use requestIdleCallback or scheduler.yield() to split work into smaller chunks that let the browser handle user input between them.

  • Debounce expensive event handlers. Input and scroll events fire at high frequency. Throttle handlers to at most once per frame using requestAnimationFrame.

  • Lazy load non-critical JavaScript. Code that handles modals, analytics, or below-the-fold features should load after the main content is interactive.

The quickest win: open DevTools Performance panel, record a click interaction, and look for yellow "Long Task" markers. Each one is a candidate for splitting.

Step 4: Eliminate CLS (7 minutes)

Layout shifts happen when elements move after initial render. Common causes and fixes:

  • Images and embeds without dimensions. Always set width and height attributes. The browser calculates aspect ratio from these and reserves space before the image loads.

  • Late-loading web fonts. Use font-display: optional to prevent invisible text from causing shifts when fonts load. Better yet, preload critical fonts with <link rel="preload" as="font">.

  • Dynamically injected content. Ads, banners, or toasts that push content down. Reserve fixed-height containers for these elements, or use position: absolute so they overlay instead of shifting layout.

  • Client-side rendering without skeletons. If your framework renders content on the client, show skeleton placeholders that match the final layout dimensions. This prevents content from jumping into view.

Quick Verification

After making changes, run Lighthouse again and compare the numbers. Focus on the mobile score — mobile devices have slower CPUs and networks, so mobile scores are typically 20-40% lower than desktop.

For ongoing monitoring, set up automated Lighthouse CI in your deployment pipeline. Track scores on every pull request to catch regressions before they reach production.

The entire audit-and-fix cycle should take under 30 minutes for most sites. The search ranking and user experience improvements compound over weeks, making this one of the highest-ROI technical improvements you can make.

Top comments (0)