DEV Community

Cover image for 🚦 Understanding Lighthouse, Web Vitals & PageSpeed Reports
Sachin Maurya
Sachin Maurya

Posted on

🚦 Understanding Lighthouse, Web Vitals & PageSpeed Reports

πŸ“˜ Introduction

Your React or Next.js app might β€œlook fast,” but is it actually fast for the user? Lighthouse and Web Vitals give you real insights into user experience performance β€” and tools like PageSpeed Insights help you catch and fix the bottlenecks.

In this post, I’ll break down what each Lighthouse metric means, how to read the PageSpeed report, and how to improve your scores with real-world React/Next.js fixes.


🚦 What is Lighthouse?

Lighthouse is an open-source tool by Google that audits:

  • Performance
  • Accessibility
  • Best Practices
  • SEO
  • PWA readiness

You can run it using:

We’re focusing on the Performance tab for this post.


πŸ“Š Key Metrics You Should Know (Web Vitals)

1. LCP (Largest Contentful Paint)

βœ… Ideal: < 2.5s
When the largest visible element (like a hero image or H1) becomes visible.

πŸ”§ Fix:

  • Use next/image with blur placeholders
  • Serve critical CSS inline
  • Lazy-load below-the-fold images

2. FID (First Input Delay)

βœ… Ideal: < 100ms
Measures how fast your app responds to the first interaction.

πŸ”§ Fix:

  • Reduce JS execution time
  • Break long tasks using requestIdleCallback
  • Move unnecessary JS to useEffect or dynamic imports

3. CLS (Cumulative Layout Shift)

βœ… Ideal: < 0.1
Measures unexpected layout shifts during loading.

πŸ”§ Fix:

  • Set width and height for all images/videos
  • Avoid inserting DOM elements without space reserved
  • Use font-display: swap

4. TBT (Total Blocking Time)

βœ… Ideal: < 200ms
How much time your page is blocked from responding due to JS.

πŸ”§ Fix:

  • Lazy load non-critical components
  • Use dynamic imports in Next.js
  • Avoid large synchronous functions

5. TTI (Time to Interactive)

When the page is fully interactive.

This metric depends on others like TBT, FID, and JS bundle size.


πŸ“₯ How to Run Lighthouse

1. In Chrome DevTools

  • Right-click β†’ Inspect β†’ Lighthouse tab β†’ Run audit
  • Choose Mobile/Desktop + what to test

2. Via PageSpeed Insights

  • Enter your deployed URL
  • Get Core Web Vitals + opportunities to improve

βš™οΈ Common React/Next.js Fixes to Boost Lighthouse Score

βœ… Use next/image instead of <img>

  • Automatically optimized
  • Lazy loads by default
  • Uses blur placeholder
import Image from 'next/image';

<Image src="/banner.png" width={800} height={400} placeholder="blur" />
Enter fullscreen mode Exit fullscreen mode

βœ… Reduce JS Bundle Size

  • Use dynamic imports (next/dynamic)
  • Tree-shake unused libraries
  • Split large components
const Settings = dynamic(() => import('./Settings'), { ssr: false });
Enter fullscreen mode Exit fullscreen mode

βœ… Preload Fonts

  • Use next/font for automatic font optimization
  • Avoid layout shift on font load
import { Inter } from "next/font/google";
const inter = Inter({ subsets: ["latin"], display: "swap" });
Enter fullscreen mode Exit fullscreen mode

βœ… Prioritize Visible Content

  • Load critical content first
  • Defer hidden sections
  • Use priority prop with next/image
<Image src="/banner.jpg" priority ... />
Enter fullscreen mode Exit fullscreen mode

βœ… Minimize Third-Party Scripts

  • Delay non-essential analytics
  • Load chat widgets after interaction
  • Offload non-critical logic with requestIdleCallback

πŸ“ˆ Track & Monitor Over Time

  • Use Lighthouse CI in GitHub Actions
  • Integrate Web Vitals reporting into production
  • Use tools like Vercel Analytics, Sentry, SpeedCurve, Calibre

🧠 Final Thoughts

You can’t improve what you don’t measure.
Lighthouse and Web Vitals are not just numbers β€” they reflect real user frustration (or joy).

Start with audits, fix one issue at a time, and your users (and Google rankings) will thank you.

Top comments (0)