Web Performance: Measuring and Improving Core Web Vitals
Your users are impatient. Slow pages frustrate visitors, increase bounce rates, and hurt your search rankings. Core Web Vitals (CWV) are Google's metrics for quantifying user experience: they measure loading, interactivity, and visual stability. In this guide, you'll learn what each metric means, how to measure them, and concrete steps to improve them.
What Are Core Web Vitals?
Core Web Vitals are three specific metrics that Google uses as part of its page experience signals:
- Largest Contentful Paint (LCP): measures loading performance. It marks the time when the largest content element (image or text block) becomes visible. Aim for LCP under 2.5 seconds.
- First Input Delay (FID): measures interactivity. It's the time from when a user first interacts (e.g., clicks a link) to when the browser is able to respond. Aim for FID under 100 milliseconds.
- Cumulative Layout Shift (CLS): measures visual stability. It quantifies unexpected layout shifts during page load. Aim for CLS under 0.1.
Note: FID is being replaced by Interaction to Next Paint (INP) as a Core Web Vital in March 2024. INP measures the latency of all interactions during a page visit. For now, focus on both FID and INP.
How to Measure Core Web Vitals
You can't improve what you don't measure. Use these tools to collect CWV data:
- Chrome User Experience Report (CrUX): provides real-world data from Chrome users. Access via PageSpeed Insights or the CrUX API.
- PageSpeed Insights: shows both lab and field data for a URL.
- Lighthouse: runs lab tests in Chrome DevTools or CI.
- Web Vitals JavaScript library: collects CWV metrics from real users in your analytics.
Start with PageSpeed Insights to get a quick overview. Then instrument your site with the web-vitals library to gather field data across your user base.
// Example: using web-vitals library
import {onLCP, onFID, onCLS} from 'web-vitals';
function sendToAnalytics(metric) {
const body = JSON.stringify(metric);
navigator.sendBeacon('/analytics', body);
}
onLCP(sendToAnalytics);
onFID(sendToAnalytics);
onCLS(sendToAnalytics);
Improving Largest Contentful Paint (LCP)
LCP is often the most challenging metric. To improve it:
- Optimize images: compress images, use modern formats like WebP or AVIF, and serve responsive sizes with
srcset. - Preload critical resources: use
<link rel="preload">for the LCP image or font. - Reduce server response time: optimize backend code, use caching, and consider a CDN.
- Eliminate render-blocking resources: defer non-critical CSS and JavaScript.
- Use a content delivery network (CDN): serve assets from locations closer to users.
Improving First Input Delay (FID) and Interaction to Next Paint (INP)
FID and INP are about responsiveness. Long JavaScript tasks block the main thread, delaying interactions. To improve:
- Break up long tasks: split large JavaScript into smaller chunks using
setTimeoutorrequestIdleCallback. - Minimize main-thread work: remove unnecessary JavaScript, use code splitting, and defer non-critical scripts.
- Optimize event handlers: avoid heavy work in event listeners; debounce or throttle where appropriate.
- Use web workers: offload expensive computations to a worker thread.
Improving Cumulative Layout Shift (CLS)
CLS measures unexpected layout shifts. Common causes include images without dimensions, ads, embeds, and dynamic content injected above existing content. To fix:
- Always include width and height attributes on images and videos, or use CSS
aspect-ratio. - Reserve space for ads and embeds: use placeholders or fixed-size containers.
- Avoid inserting content above existing content unless triggered by user interaction.
- Use transform animations instead of properties that trigger layout.
Tools and Workflow for Continuous Improvement
Performance is not a one-time fix. Integrate CWV checks into your development workflow:
- Run Lighthouse in CI to catch regressions.
- Monitor field data with the web-vitals library and your analytics platform.
- Set performance budgets and alert when metrics degrade.
- Use Chrome DevTools Performance panel to profile runtime issues.
FAQ
What are the current thresholds for Core Web Vitals?
As of 2024, the thresholds are: LCP ≤ 2.5s, FID ≤ 100ms, CLS ≤ 0.1. For INP, the threshold is ≤ 200ms. These are assessed at the 75th percentile of page loads.
How often should I measure Core Web Vitals?
Monitor continuously in production using real user monitoring (RUM). Also run lab tests (e.g., Lighthouse) on each deployment to catch regressions early.
Does improving Core Web Vitals really affect SEO?
Yes, Core Web Vitals are part of Google's page experience signals. While content remains king, good CWV can give you a competitive edge in search rankings.
Ready to optimize your images for better LCP? Try our free Image Compressor to reduce file sizes without losing quality.