Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Web Performance & Core Web Vitals
  1. 1.Introduction to Web Performance & Business Impact
  2. 2.Core Web Vitals & Practical Measurement Tools
  3. 3.Optimizing the Critical Rendering Path & Basic Asset Delivery
  4. 4.JavaScript Performance & Bundle Optimization
  5. 5.Image, Video, and Media Optimization Strategies
  6. 6.Network Performance: HTTP/2, Caching, and CDNs
  7. 7.Resource Hints & Advanced Loading Strategies
  8. 8.Frontend Architectures & Server-Side Rendering Performance
  9. 9.Performance Budgets, RUM, and Continuous Monitoring
  10. 10.Advanced Browser APIs & Offloading Work with Workers
Web Performance & Core Web Vitals
02

Web Fundamentals · Lesson 2 of 10 · 4 min

Core Web Vitals & Practical Measurement Tools

In an interview, you must be able to define the three Core Web Vitals, explain how they're measured, and describe the trade-off between lab and field data.

After this, you'll be able to answer the common question: "What are Core Web Vitals and how would you measure them for our application?" You will know the three key metrics, the tools to measure them, and the critical difference between lab and field data.

The Three Vitals You Must Know

Core Web Vitals are specific, user-centric metrics that quantify key aspects of the user experience. There are three.

Largest Contentful Paint (LCP) measures loading performance. It marks the point when the largest image or text block in the viewport becomes visible. A good LCP is 2.5 seconds or less.

Interaction to Next Paint (INP) measures interactivity. It assesses the time from a user interaction (like a click or keypress) until the next frame is painted in response. A good INP is 200 milliseconds or less.

Cumulative Layout Shift (CLS) measures visual stability. It quantifies how much unexpected layout shifts affect the user experience. A good CLS score is 0.1 or less.

INP officially replaced First Input Delay (FID) as a Core Web Vital in March 2024. Mentioning this transition shows you are current with web standards. FID only measured the delay of the first interaction, while INP measures the full latency of all interactions.

Lab vs. Field Data: The Most Common Trap

Performance data comes from two sources: the lab or the field. Knowing the difference is non-negotiable.

Lab data is collected in a controlled, simulated environment. This is what you get when you run Lighthouse in Chrome DevTools on your machine. It's consistent, reproducible, and essential for debugging.

Field data, or Real User Monitoring (RUM), is collected from actual users on your site. This data reflects real-world device capabilities, network conditions, and user behavior.

The trap: Believing your local Lighthouse score is the truth. A 98 on your high-end laptop connected to fiber optic internet means nothing if your users on mid-range mobile devices with spotty 4G have a terrible experience.

In an interview, always state that field data is the source of truth for user experience, while lab data is the primary tool for debugging and testing fixes before they ship. Google uses field data from the Chrome User Experience Report (CrUX) as a ranking signal.

How to Talk About Measurement Tools

You'll be asked which tools you use. Name these and explain how they relate.

Lighthouse is the open-source auditing engine that generates a performance report. It runs locally in Chrome DevTools (Audits/Lighthouse tab) and is the canonical source of lab data.

PageSpeed Insights (PSI) is a web-based tool that does two things: it runs Lighthouse on a given URL (lab data) and, if the site has enough traffic, it displays its field data from the Chrome User Experience Report.

Chrome User Experience Report (CrUX) is Google's public dataset of field data from real Chrome users. This is the data PSI shows you in the "Discover what your real users are experiencing" section.

Google Search Console provides a Core Web Vitals report for your site based on CrUX data. If Search Console says your site is failing, it is failing, regardless of your local Lighthouse score.

Measuring Vitals Programmatically with PerformanceObserver

For collecting your own field data (RUM), you use the PerformanceObserver browser API. It allows you to subscribe to performance events as they happen in the browser.

This is how you would start building a basic RUM solution. The observer's callback is fired when new performance entries (like layout-shift) are recorded.

// A simple RUM collector for LCP and CLS.
function observeVitals() {
  let cls = 0;
  
  const observer = new PerformanceObserver((entryList) => {
    for (const entry of entryList.getEntries()) {
      // Sum up layout shifts that were not caused by recent user input.
      if (entry.entryType === 'layout-shift' && !(entry as PerformanceLayoutShift).hadRecentInput) {
        cls += (entry as PerformanceLayoutShift).value;
      }
      // LCP can change as the page loads. The last entry is the final one.
      if (entry.entryType === 'largest-contentful-paint') {
        console.log('LCP candidate:', entry.startTime);
      }
    }
  });

  observer.observe({
    type: ['largest-contentful-paint', 'layout-shift'],
    buffered: true,
  });

  // Report final values before the page is unloaded.
  window.addEventListener('pagehide', () => {
    // In a real app, you'd send this to an analytics endpoint.
    console.log(`Final CLS: ${cls.toFixed(4)}`);
  }, { once: true });
}

observeVitals();

The trap: Trying to implement INP measurement yourself. INP is difficult to measure correctly. It requires tracking the full latency of all user interactions, attributing them correctly, and finding the p98 (98th percentile) interaction, not just the single worst one.

The correct approach, both in production and in an interview answer, is to use a library. Google maintains web-vitals for this purpose. It handles all the complexity.

import { onINP } from 'web-vitals';

onINP(metric => {
  // Logs the INP value for the current page load.
  console.log(metric);
  
  // Send to your analytics endpoint:
  // const body = JSON.stringify({ [metric.name]: metric.value });
  // navigator.sendBeacon('/analytics', body);
});

Try it

Use PageSpeed Insights on a site you use daily. Compare the "real users" field data to the "performance issues" lab data. Note the differences in LCP and INP. Find the LCP element identified in the Lighthouse report and think about why it was the largest.

Next: We'll focus on the first vital in Optimizing the Critical Rendering Path & Basic Asset Delivery.

Lock it in — apply this lesson under interview conditions.

Try an AI mock interview
Previous

Introduction to Web Performance & Business Impact

Next

Optimizing the Critical Rendering Path & Basic Asset Delivery