Course contentsShow
← JavaScript
Lesson 1926 of 2,72340. PerformanceFree lesson

Real User Monitoring Metrics

Tracking Time to First Byte, First Contentful Paint, and Largest Contentful Paint in production.

Real User Monitoring Metrics

You'll learn how to track Time to First Byte, First Contentful Paint, and Largest Contentful Paint to understand real user experience in production.

What Is Real User Monitoring?

Real User Monitoring (RUM) goes beyond synthetic tests in your lab. Instead of measuring performance on your machine, you capture timing data from actual users in the wild—across different devices, networks, and conditions. Three critical metrics tell you when users start seeing your page:

Time to First Byte (TTFB): How long until the browser receives the first byte of the server response. This measures server speed and network latency.

First Contentful Paint (FCP): When the first text, image, or canvas element appears on screen. Users finally see something.

Largest Contentful Paint (LCP): When the largest visible content element finishes rendering. This is typically when the page feels "loaded."

Tracking These Metrics

The Performance Observer API (from your previous lesson) makes RUM practical:

const observer = new PerformanceObserver((list) => {
  for (const entry of list.getEntries()) {
    if (entry.name === 'first-contentful-paint') {
      console.log('FCP:', entry.startTime, 'ms');
      sendToAnalytics({ metric: 'fcp', value: entry.startTime });
    }
  }
});

observer.observe({ type: 'paint', buffered: true });

For LCP, observe largest-contentful-paint:

new PerformanceObserver((list) => {
  const entries = list.getEntries();
  const lastEntry = entries[entries.length - 1];
  console.log('LCP:', lastEntry.startTime, 'ms');
  sendToAnalytics({ metric: 'lcp', value: lastEntry.startTime });
}).observe({ type: 'largest-contentful-paint', buffered: true });

For TTFB, use the Navigation Timing API:

const navTiming = performance.getEntriesByType('navigation')[0];
const ttfb = navTiming.responseStart - navTiming.requestStart;
console.log('TTFB:', ttfb, 'ms');

Key Takeaway: RUM metrics (TTFB, FCP, LCP) reveal how real users experience your site's speed—capture them with Performance Observers and send aggregated data to your analytics backend to spot patterns across your user base.