Performance Metrics and Lighthouse
🎯 Introduction
This is the final article in the Performance Optimization course. We have covered lazy loading, debouncing and throttling, caching strategies, and reducing build output. One question remains: how do you prove an optimization worked?
Saying a page feels faster is not convincing evidence. By the end of this article, you will understand Web Vitals, use Chrome's built-in Lighthouse to assess pages and interpret its recommendations, and find long tasks in the Performance panel. Your optimizations will have data to support them.
🧱 Why Quantify Performance?
Imagine spending two days implementing image lazy loading on the home page and telling your manager it is much faster. If you cannot answer how much faster, the value of those two days becomes harder to demonstrate.
The complete workflow is measure a baseline, optimize, then measure again and compare. Without a baseline, there is nothing to compare against. Intuition can also lead you toward the wrong cause: images may look like the bottleneck when synchronous JavaScript is actually blocking rendering.
Measurements give the team a shared language. Agreeing that “LCP should stay within 2.5 seconds” is clearer than everyone saying the page feels smooth. Web Vitals provides that common language.
⚖️ Core Web Vitals
Web Vitals is Google's set of page experience metrics. Its three core metrics, known as Core Web Vitals, address loading performance, responsiveness, and visual stability. Their thresholds are publicly documented, objective benchmarks. Let's examine each one.
LCP: Loading Performance
LCP (Largest Contentful Paint) marks when the page's main visible content is rendered—typically a large image or heading in the initial viewport. A good value is ≤ 2.5 seconds.
Think of opening a page as visiting a restaurant. LCP is when the main course arrives. Diners care about when they can eat, rather than when the kitchen started preparing ingredients.
For slow LCP, common improvements reduce the size and number of initial-view resources, including image compression, lazy loading, and preloading critical resources. These were covered in Loading Optimization.
INP: Responsiveness
INP (Interaction to Next Paint) measures the delay between user interactions, such as clicks or typing, and the next visual update. It assesses how responsively the page reacts. A good value is ≤ 200 milliseconds.
Continuing the restaurant analogy, INP is how long it takes a server to respond when you raise your hand. Beyond 200 milliseconds, users may start wondering whether the page has frozen.
High INP often means long tasks are occupying the main thread. Common remedies include splitting expensive tasks and debouncing or throttling high-frequency events, as covered in Rendering Optimization.
CLS: Visual Stability
CLS (Cumulative Layout Shift) measures the cumulative impact of unexpected element movement during page loading. A good score is ≤ 0.1. It is a unitless score, not a duration.
You have probably tried to click a button just as an image loads and pushes it down, causing you to click an ad instead. That is a layout shift, much like a restaurant table suddenly wobbling.
To reduce high CLS, reserve space for images and ads with explicit dimensions, and avoid inserting new elements above existing content.
🛠 Assessing Pages with Lighthouse
Now that you know the benchmarks, how does your page perform? Chrome's built-in Lighthouse can assess it without installing extra software.
Open the page you want to test, press F12 to open DevTools, and switch to the Lighthouse panel:
- Under Categories, select Performance. You can leave categories such as Accessibility and SEO unchecked to keep the report focused.
- Select Mobile. Mobile testing uses stricter conditions that more closely reflect constrained devices and networks.
- Click Analyze page load and wait several dozen seconds for the report.
Understanding the Performance Score
The report starts with a score from 0 to 100: 90–100 is good (green), 50–89 needs improvement (orange), and 0–49 is poor (red). It combines weighted performance metrics such as LCP, INP, CLS, and FCP. Individual values below the score help identify which metric is holding the page back.
Understanding Recommendations
Further down, focus on two sections:
- Opportunities: actionable improvements such as compressing images or removing render-blocking resources, with estimated time savings.
- Diagnostics: deeper analysis, such as a breakdown of main-thread work and excessive JavaScript execution time, explaining the causes behind the score.
Read the report by finding weak metrics first, then looking for relevant recommendations in Opportunities. The score is a reference; the real value is knowing what to optimize next. Lighthouse measures a single visit on your machine, producing lab data that may differ from real user experience. We will return to this distinction below.
🧰 The Performance Panel: Finding Long Tasks
Lighthouse can reveal slow responsiveness, but which code causes it? Use the Chrome DevTools Performance panel to investigate.
Start a recording, perform representative actions such as scrolling a list or clicking buttons, then stop. The resulting main-thread timeline shows tasks as colored blocks. Focus on tasks lasting longer than 50 milliseconds, known as long tasks, which are marked with red corner indicators. Long tasks occupy the main thread and delay responses to clicks, making them a common cause of high INP.
Select a long task to inspect its function calls and follow the call stack to the expensive code. Then apply a targeted remedy: split heavy loops or debounce and throttle overly frequent handlers. Rendering Optimization explains these techniques; now you know when to use them.
💡 Collecting Metrics from Real Users
Lighthouse has an inherent limitation: it measures performance on your machine and connection. Real users have varied devices and networks, and their experiences can differ substantially. Google's official web-vitals npm package collects Web Vitals in real user environments.
The following example was tested with Node.js v22 and web-vitals v5.x. Install it with:
# Local environment: Node.js v22, web-vitals v5.x
pnpm add web-vitals
Then collect the three core metrics in your application's entry file:
import { onLCP, onINP, onCLS } from 'web-vitals';
// Each callback runs when its metric is determined; metric.value contains the measured value
onLCP((metric) => {
console.log('LCP:', metric.value);
});
onINP((metric) => {
console.log('INP:', metric.value);
});
onCLS((metric) => {
console.log('CLS:', metric.value);
});
In production, replace console.log with reporting logic that sends values to your analytics endpoint. This lets you monitor actual user experience over time. For now, understand the API; you do not need to build a reporting system yet.
⚡ Performance Optimization Is a Cycle
This completes the course. Let's review the themes of the preceding five articles:
- Performance Optimization Overview: understand the five areas—loading, rendering, caching, builds, and metrics.
- Loading Optimization: deliver resources faster through lazy loading, preloading, and code splitting.
- Rendering Optimization: keep interactions smooth with debouncing, throttling, and virtual lists.
- Caching Strategies: make repeat visits nearly instant through fresh cache reuse and revalidation.
- Build Output Optimization: reduce resource size at the source through bundle analysis and tree shaking.
This article connects them through measure → optimize → validate. Measure with Web Vitals and Lighthouse to identify weaknesses, apply targeted techniques from the previous articles, then measure again to confirm improvement. Repeat the cycle. Performance work has no permanent finish line; effective optimization follows the data through successive iterations.
❓ Questions and Answers
Q1: Is it normal for Lighthouse scores to vary between runs?
Yes. Machine load and network fluctuations affect results, so small variations are normal. Run several audits and look for trends. Focus on the scale of metric values rather than a one- or two-point score difference.
Q2: Which should I optimize first: LCP, INP, or CLS?
Prioritize metrics outside the good range. Once all are healthy, consider which is closest to its threshold and easiest to improve. Follow the data rather than personal preference.
Q3: Does a high local Lighthouse score mean everything is fine?
Not necessarily. Your local device and network may be better than those of your users. A high score is a good foundation, but confirming actual experience requires production data from tools such as web-vitals.
Q4: Is every task longer than 50 milliseconds a problem?
A long task is a warning signal, not something that must always be eliminated. Check whether it affects a critical interaction. If it occupies the main thread when the user clicks, it can harm INP and deserves priority.
Q5: How do these metrics relate to the techniques in previous articles?
Metrics provide the diagnosis; optimization techniques provide the treatment. Slow LCP points toward loading and build output improvements, high INP toward rendering improvements, and caching improves loading on repeat visits. Diagnose first, then choose a remedy.
🧪 Exercises
Exercise 1: Assess a page. Open one of your project pages in an incognito window and run a Performance audit in the DevTools Lighthouse panel. Record LCP, INP, and CLS, compare them with the good thresholds, and explain which one you would prioritize.
Exercise 2: Collect metrics with web-vitals. Install web-vitals in a local project using Node.js v22 and web-vitals v5.x. Complete the code so each metric callback logs an English label and a rounded value:
import { onLCP, onINP, onCLS } from 'web-vitals';
// Write your code here: log LCP with onLCP, rounding with Math.round
// Write your code here: log INP with onINP, rounding with Math.round
// Write your code here: log CLS with onCLS; CLS is fractional, so keep two decimal places if needed
Run the project, open the console, and interact with the page by clicking and scrolling. Observe how the timing of the three metric outputs differs.
🎉 You now know how to use performance metrics and Lighthouse, completing the Performance Optimization course! Support each optimization with data and keep improving your pages through the measure → optimize → validate cycle.
