LearnAI ToolsCareerPractice BuildsPlayContact
Lesson 4718 min read

Performance Optimization

Practical techniques for keeping a Next.js app fast — bundle analysis, dynamic imports, and Core Web Vitals.

Core Web Vitals

Core Web Vitals are the metrics Google uses to measure real-world user experience, and they also factor into search ranking — making them a useful, concrete target for performance work.

MetricMeasuresGood Target
LCP (Largest Contentful Paint)How quickly the main content appearsUnder 2.5s
INP (Interaction to Next Paint)Responsiveness to user interactionUnder 200ms
CLS (Cumulative Layout Shift)Visual stability while loadingUnder 0.1

Analyzing Your Bundle

@next/bundle-analyzer visualizes exactly what's inside your production JavaScript bundle, making it easy to spot an unexpectedly large dependency.

npm install --save-dev @next/bundle-analyzer
// next.config.js
const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
});
module.exports = withBundleAnalyzer({});
ANALYZE=true npm run build

Dynamic Imports

For a heavy component that isn't needed immediately — a rich text editor, a chart library — next/dynamic loads it separately, only when it's actually rendered.

import dynamic from 'next/dynamic';
const RichTextEditor = dynamic(() => import('./RichTextEditor'), {
loading: () => <p>Loading editor…</p>,
ssr: false, // skip server rendering for browser-only libraries
});

Streaming and Suspense, Revisited

As covered in the loading UI lesson, wrapping slow, non-critical parts of a page in <Suspense> lets the fast parts render immediately — directly improving perceived LCP, since visitors see meaningful content sooner.

A Performance Checklist

  • Use next/image for every image, with priority on above-the-fold images only.
  • Use next/font instead of a runtime <link> tag for web fonts.
  • Push "use client" boundaries as deep as possible (see the composition patterns lesson).
  • Dynamically import large, non-critical components.
  • Run Promise.all for independent data fetches instead of awaiting them sequentially.
  • Choose the right rendering strategy (SSG/ISR) for content that doesn't need to be dynamic.

FAQs

Yes — automatic code splitting per route, image/font optimization, and streaming are all on by default; these techniques address what's left after those defaults.

Lighthouse in Chrome DevTools for a quick local check, and Vercel Speed Insights (or Google's CrUX report) for real user data in production.

Summary

Between Next.js's built-in optimizations and deliberate techniques like dynamic imports and parallel fetching, most performance problems have a clear, known fix. Next, you'll deploy a finished app to production.

Next Lesson →

Deploying Next.js Apps