← Back to Frontend, page 1

frontend-0007 · Easy fresher

What is the difference between lab data and field data for web performance, and how do you collect field data yourself?

Lab data comes from a controlled test run, such as Lighthouse, and is repeatable and good for debugging. Field data comes from real visits, so it shows the real mix of devices and networks, and it is what Core Web Vitals are judged on. Collect it yourself with a real user monitoring (RUM) script that sends metrics with navigator.sendBeacon.

Full answer

Lab data is a synthetic test. A tool loads the page with a fixed device profile and a fixed network, so two runs are easy to compare. It is the right tool for debugging and for catching regressions in CI. It cannot tell you what real users see, because real users have older phones, slow networks, ad blockers, cached resources and logged-in states.

Field data is collected from real visits. Two common sources:

  • CrUX (Chrome User Experience Report) is a public data set from opted-in Chrome users. It is free and gives origin-level and URL-level percentiles, but with a delay and only for pages with enough traffic.
  • RUM (real user monitoring) is your own script. It records metrics in each visit and sends them to your server. It can add custom data such as the route, the release number and the device class.

A RUM script should do four things:

  1. Read the metrics from the PerformanceObserver API, or from the web-vitals library.
  2. Send once per page view when the page is hidden, not on unload, because unload is unreliable and can block back-forward caching.
  3. Use navigator.sendBeacon, which queues the request so it survives the page closing.
  4. Add a label for the page template and the release, so a regression can be traced.

Example numbers: a lab run on a fast laptop shows LCP at 1.4 seconds, while the field 75th percentile on mobile is 3.9 seconds. Both are true. The field number decides the Core Web Vitals result.

Lab and field data answer different questions, so a strong team uses both.

javascript
const metrics = { route: location.pathname, release: '2026-12-04' };

new PerformanceObserver((list) => {
  metrics.lcp = Math.round(list.getEntries().at(-1).startTime);
}).observe({ type: 'largest-contentful-paint', buffered: true });

function flush() {
  if (!metrics.sent) {
    metrics.sent = true;
    navigator.sendBeacon('/rum', JSON.stringify(metrics));
  }
}
document.addEventListener('visibilitychange', () => {
  if (document.visibilityState === 'hidden') flush();
});

Run in headless Chrome 156 through Playwright. Two full runs gave the same results. The page was hidden by script, and the test captured the beacon request. It showed one request with the route and an LCP value. No real server received it.

Key points

  • Lab data is controlled and repeatable, so it suits debugging and CI.
  • Field data is real users and is what Core Web Vitals are assessed on.
  • CrUX is public but delayed. RUM is your own and more detailed.
  • Send RUM data on visibilitychange with sendBeacon, not on unload.

Common mistakes

  • Believing a green Lighthouse score means real users are fast.
  • Sending the beacon from an unload handler.
  • Collecting metrics without a page or release label, so no fix can be traced.
  • Treating CrUX as real-time.

Follow-ups

  • Why can field and lab LCP differ by a large factor?
  • What do you do when a page has too little traffic for CrUX?
  • Why use sendBeacon instead of fetch in a page-hide handler?

Tips

  • Say that you would use lab data to find the cause and field data to confirm the fix.
  • Mention sampling when traffic is large, to control cost.