Skip to main content
Sosho Studio logo
Browser model on a fast track with a performance gauge
Next.jsFrontendPublished Updated

Optimizing Performance in Next.js (App Router)

A practical guide to faster Next.js App Router sites: Server vs Client Components, images, fonts, static rendering and caching, dynamic imports, and Core Web Vitals.

Quick answer

To speed up a Next.js site, keep most of the page as Server Components and make only interactive parts Client Components; load images with next/image at the right size and give priority only to the main above-the-fold image; load fonts with next/font without layout shift; pre-render pages statically where possible and cache data deliberately; defer heavy libraries with dynamic import; and measure the result with Core Web Vitals on real mobile devices.

Split Server and Client Components correctly

In the App Router, components are Server Components by default and ship no JavaScript to the browser. Wherever you write "use client", that component and everything it imports enter the user's bundle, so push that boundary as low as possible, close to the actual interactive button or form.

A useful pattern is to build static parts in a Server Component and pass them as children to the interactive component. The menu or slider stays interactive, but the content inside it adds no extra JavaScript.

Images and LCP

On most pages the largest above-the-fold element is an image, and it decides your LCP.

  • Use next/image with width and height, or fill with correct sizes, so CLS stays at zero
  • Give priority only to the main above-the-fold image; let the rest lazy-load
  • Never lazy-load the LCP image, and use WebP or AVIF formats
  • Store images at their largest display size, not several times larger

Fonts without layout shift

next/font self-hosts fonts on your own domain, builds only the subset you need, and tunes a fallback font to reduce text shifting when the real font loads. For Persian fonts too, load only the weights you actually use and prefer the woff2 format.

Static rendering, streaming, and caching

A page that is the same for every user should be built at build time; for dynamic routes such as articles, use generateStaticParams. Reading cookies or headers moves a page to dynamic rendering, so use them only when really needed.

If part of a page is slow, wrap it in Suspense so the rest streams and displays sooner. In recent Next.js versions, data caching has to be declared explicitly; read the documentation for the exact version you use before deciding.

A JavaScript budget

Every kilobyte of JavaScript must be downloaded, parsed, and executed on mobile, and it directly affects INP and time to interactive.

  • Load charts, editors, maps, and 3D scenes with dynamic import only when needed
  • Inspect the bundle with an analyzer and replace large, rarely used libraries
  • Defer third-party scripts with next/script and a suitable strategy such as lazyOnload
  • Do not load occasionally needed widgets until the user interacts

Measure the right way

Core Web Vitals thresholds for a good experience: LCP up to 2.5 seconds, INP up to 200 milliseconds, and CLS up to 0.1. Lighthouse gives lab data that helps find problems, but Google's yardstick is real-user data, visible in PageSpeed Insights and Search Console.

After every significant change, measure the same key pages on mobile again and compare the results.

Frequently asked questions

Is the App Router faster than the Pages Router?

It can be, because Server Components send less JavaScript and support streaming. But final speed depends on the implementation; an App Router full of Client Components can still be slow.

What is INP?

Interaction to Next Paint measures how quickly a page responds to user interactions such as clicks or typing, and it replaced FID in Core Web Vitals in March 2024. Up to 200 milliseconds counts as good.

Should every page be static?

Any page that is the same for everyone is best static. User-specific pages, such as dashboards or carts, should stay dynamic, with only shareable data cached.