Menu

Measuring Performance and Core Web Vitals

Lesson 2: Measuring Performance and Core Web Vitals

What are Core Web Vitals?

Core Web Vitals are Google's main measures of real-user experience. They also influence search rankings.

Metric Measures Good Common Next.js fixes
LCP (Largest Contentful Paint) Loading: when the main content appears ≤ 2.5 s priority on hero image, static rendering, streaming
INP (Interaction to Next Paint) Responsiveness: delay after a click or key press ≤ 200 ms Less client JavaScript, smaller Client Components, transitions
CLS (Cumulative Layout Shift) Visual stability: unexpected movement ≤ 0.1 next/image sizes, next/font, matching skeletons

Example

Send real-user metrics to your analytics:

// app/web-vitals.tsx
'use client';
import { useReportWebVitals } from 'next/web-vitals';

export function WebVitals() {
  useReportWebVitals((metric) => {
    navigator.sendBeacon('/api/vitals', JSON.stringify({
      name: metric.name,   // 'LCP', 'INP', 'CLS', ...
      value: metric.value,
      page: window.location.pathname,
    }));
  });
  return null;
}

Render <WebVitals /> once in the root layout.

How it works

Tool Data type Use for
Lighthouse (Chrome DevTools) Lab: one simulated load Quick checks during development
PageSpeed Insights Lab + field data from real Chrome users Checking public pages
useReportWebVitals / Vercel Speed Insights Field: your real users Ongoing monitoring
Chrome DevTools Performance panel Detailed traces Finding slow scripts and long tasks

Always measure a production build (npm run build && npm run start) on a throttled connection. Dev mode is not representative.

Common mistakes

Mistake Effect Fix
Testing only on a fast laptop Problems on mobile are missed Throttle CPU and network in DevTools
Chasing a perfect Lighthouse score Effort on low-impact tweaks Focus on field data and the worst pages
Large client-side libraries for small features Poor INP and slow loads Move work to Server Components or lazy-load it

Key takeaways

  • Track LCP, INP, and CLS with real-user data, not just lab tests.
  • Most fixes are using Next.js features correctly: images, fonts, server rendering, and less client JavaScript.

Try it: Run Lighthouse on the LearnHub home page in production mode, note the LCP element, and improve it.


Nextjs Tutorial

J

Jebasta





Get in Touch For Details