How to Improve Core Web Vitals: Optimizing LCP, CLS, and INP
Core Web Vitals — Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), and Interaction to Next Paint (INP) — are crucial metrics for evaluating a web page’s user experience. They play a significant role in search engine rankings and user satisfaction. As such, web developers must focus on diagnosing and optimizing these metrics to ensure a seamless browsing experience.
This guide provides step-by-step instructions on improving these metrics effectively, focusing on practical solutions for diagnosing and addressing bottlenecks.
Understanding Core Web Vitals and Their Importance
Core Web Vitals are part of Google’s web performance metrics essential for delivering a good user experience. Let’s clarify what they measure:
- Largest Contentful Paint (LCP): Measures how fast the largest visible element (e.g., an image or a text block) on the viewport is rendered. A good LCP score is under 2.5 seconds for 75% of users.
- Cumulative Layout Shift (CLS): Evaluates visual stability by measuring unexpected shifts during a page's life cycle. A good CLS score is below 0.1.
- Interaction to Next Paint (INP): Indicates interaction responsiveness. INP has replaced First Input Delay (FID) as a more accurate measure of interactivity. A good INP score is under 200 milliseconds.
These metrics directly influence user engagement and conversions. If you struggle with them, start by understanding each metric’s underlying causes and address those systematically, as outlined below.
Diagnosing LCP Bottlenecks
To address LCP issues, the first step is pinpointing where the delays occur during loading.
Common LCP Bottleneck Sources
- Time to First Byte (TTFB): The time required for the browser to receive the first byte after a page request.
- Resource Load Delay: The delay before the LCP resource starts loading.
- Resource Load Time: The time taken for the LCP resource (e.g., an image) to fully load.
- Element Render Delay: The delay before rendering the LCP element once it is fully loaded.
Tools to Diagnose
- Chrome DevTools: Use the Performance tab to analyze critical sub-parts of LCP.
- Google Lighthouse: Provides a detailed breakdown of LCP-related delays.
- WebPageTest or your browser's network waterfall for resource priorities and requests.
Ensure you accurately identify whether issues stem from client-side inefficiencies, network constraints, or server-side delays.
Optimizing LCP
LCP optimizations fall under four primary categories:
steps
Prioritize the LCP Resource
- Use
<link rel="preload">to preload the image or font that constitutes the LCP element. - Add
fetchpriorityin<img>tags for better prioritization in modern browsers.
html<link rel="preload" href="image.jpg" as="image"> <img src="image.jpg" fetchpriority="high">- Use
Minimize Element Render Delay
- Pre-render critical UI components to eliminate dependency on JavaScript rendering.
- Optimize render-blocking resources like CSS and scripts by inlining critical CSS and compressing files.
Optimize the LCP Resource
- Compress and resize images to appropriate dimensions using modern formats like WEBP or AVIF.
- Optimize fonts using variable fonts or font-display strategies.
Reduce TTFB
- Address server-side latency issues by:
- Optimizing database queries.
- Enabling server-side caching.
- Using a Content Delivery Network (CDN) to reduce latency.
- Address server-side latency issues by:
Optimizing CLS and INP
Fixing CLS Issues
Common causes of poor CLS scores include:
- Unsized images: Always specify dimensions for images and videos using width and height attributes or CSS.
- Dynamic content: Reserve space for elements dynamically injected into the DOM to prevent layout shifts.
- Slow-loading web fonts: Use font-display CSS to ensure text is visible during font loading.
For example:
<style>
img {
width: 100%;
height: auto;
}
</style>Transitioning to INP from FID
Unlike the older FID metric, INP measures interaction responsiveness across the entire lifecycle of the page. To ensure a good INP score:
- Reduce JavaScript execution time to enable faster interactions.
- Optimize event handlers for critical elements.
- Avoid long task blocks that can delay input processing.
Verification and Real-World Testing
After implementing fixes, verify your optimizations using field testing and lab tools.
steps
- Run Lighthouse Tests
- Use Google Lighthouse to verify improvements in LCP, CLS, and INP scores.
# Open Chrome DevTools
lighthouse # Select Performance Audit
# Review LCP, CLS, and INP metrics in the generated reportValidate with Web Vitals Extension
- Use the Chrome Web Vitals extension to monitor real-time web performance.
Analyze Field Data
- Use the Chrome UX Report (CrUX) and PageSpeed Insights for real-world, aggregated Core Web Vitals data.
- Adjust optimizations as needed based on performance trends and outliers.
FAQ
What causes high LCP times?
High LCP times are often caused by slow server response times (TTFB), unoptimized resource loading delays, or rendering inefficiencies for the largest visible element.
How do I resolve CLS issues?
To reduce CLS, size media elements explicitly, reserve space for dynamic content, and ensure fonts load efficiently using font-display.
Why was INP introduced instead of FID?
INP provides a more comprehensive score for interactivity as it measures responsiveness throughout the lifecycle of the page, unlike FID, which only looks at the first user action.
Can a CDN help with Core Web Vitals?
Yes, a CDN can significantly reduce both TTFB and resource load latency by caching content closer to users.
Official reference: Core Web Vitals.