Performance
Performance Monitoring
Core Web Vitals are Google's key metrics for real user experience. They cover three things: loading (LCP), interactivity (originally FID, now INP) and visual stability (CLS). Together they tell you how fast the page loads, how quickly users can interact, and whether the layout stays put while it loads.
Loading
LCP
Largest Contentful Paint
Interactivity
INP
Interaction to Next Paint
Visual stability
CLS
Cumulative Layout Shift
In March 2024 INP replaced FID as the official interactivity Core Web Vital. FID (good under 100 ms, poor over 300 ms) is still worth knowing for interviews.
The Loading Timeline
Start
Navigation begins, blank screen
FCP
First text or image appears
LCP
Main content is rendered
Interaction
FID / INP measure the response
1. FCP and LCP
First Contentful Paint (FCP)
- The time from when the page starts loading until the first piece of content becomes visible.
- That content can be text, an image or any visual element - it shows the browser has started rendering.
- It marks the moment users stop staring at a blank screen.
- Example: if a heading or logo appears after 1-2 seconds, users feel the page has started loading.
Largest Contentful Paint (LCP)
- The time until the largest visible element - a hero image, banner or main content block - is fully rendered.
- It marks when the page's main content has loaded and the page becomes meaningful.
- One of the most important metrics for perceived loading speed.
- Example: if the main banner or product image loads within 2.5 seconds, the page feels fast and complete.
2. Cumulative Layout Shift (CLS)
- Measures how much elements move unexpectedly while the page loads.
- It represents visual stability: does the layout stay fixed or jump around as content arrives?
- High CLS makes users click the wrong thing or lose their place while reading.
- Example: a button moves down when an image loads late, causing a misclick.
- Fix: reserve space for late content - set
width/heighton images and give ad slots a fixed size.
Reserve space so late content can't push the page around
<!-- The browser knows the box size before the image arrives -->
<img src="hero.webp" width="1200" height="600" alt="Hero" />
<style>
.ad-slot { min-height: 250px; } /* keep room for the ad */
</style>3. First Input Delay (FID)
- The time between a user's first interaction (click, tap or key press) and when the browser can start handling it.
- The delay happens when the main thread is busy, usually running heavy JavaScript.
- It reflects how responsive the app feels the moment someone tries to use it.
- Example: a user clicks "Buy Now" but nothing happens because the browser is still running scripts.
4. Interaction to Next Paint (INP)
- The time from a user interacting with the page (click, tap, typing) until the next visual update appears.
- It covers the full interaction: input delay, event handler processing and rendering - more complete than FID.
- It looks at interactions across the whole visit, not just the first one.
- Example: a user clicks a button to open a modal, but heavy processing delays it - INP is high.
- Good INP is 200 ms or less; poor is over 500 ms.
Browser-Centric vs User-Centric Metrics
| Criteria | Browser-Centric Metrics | User-Centric Metrics |
|---|---|---|
| Focus | Technical aspects of loading and rendering | User experience and perception |
| Measured | In the browser with lab/testing tools | On real user devices (field data) |
| Data type | Lab data (controlled environment) | Field data (real-world usage) |
| Purpose | Debugging and optimizing code | Improving actual user satisfaction |
| Matches perception | Not always | Closely |
| Responsiveness | Focuses on loading phases | Includes FID, INP, interaction delays |
| Usage | Finding bottlenecks | Prioritizing UX and business impact |
| Monitoring | Synthetic testing tools | Real User Monitoring (RUM) |
| Reliability | Consistent but not realistic | Realistic but varies across users |
| SEO impact | Limited direct impact | Strong (Core Web Vitals) |
| Examples | TTFB, DOMContentLoaded, Load time | LCP, CLS, FID, INP |
| Tools | DevTools, Lighthouse (lab mode) | Chrome UX Report, analytics, RUM tools |
| Optimization approach | Code level (bundling, caching) | UX level (loading feel, interactivity) |
| Business impact | Indirect | Direct (conversion, retention) |
| Best practices | Debug, optimize resources, set performance budgets | Focus on Core Web Vitals, monitor real users, balance speed and experience |
Collect Core Web Vitals from real users with the web-vitals library
import { onLCP, onINP, onCLS } from 'web-vitals';
function send(metric) {
// e.g. forward to your analytics endpoint
navigator.sendBeacon('/analytics', JSON.stringify(metric));
}
onLCP(send);
onINP(send);
onCLS(send);