websitespeed.dev
Blog

How to reduce JavaScript in a Next.js app

2026-12-04 · 3 min read

Next.js is fast by default, but a few imports in the wrong place can add hundreds of kilobytes to every page. Total Blocking Time carries the most weight in the performance score, so less JavaScript is the most direct way to raise it.

1. See what you ship

Run a speed test on the deployed app and look at the weight of the JavaScript chunks. For a breakdown by package, use the official bundle analyzer.

2. Import heavy components dynamically

Charts, editors and maps should load only on the pages that show them:

import dynamic from "next/dynamic";

const Chart = dynamic(() => import("./Chart"), {
  loading: () => <p>Loading chart...</p>,
});

3. Keep components on the server

In the App Router, components are server components unless a file starts with the use client directive. Put that directive as low in the tree as possible, on the button or form that needs it, not on the whole page.

4. Use next/image

Plain img tags skip resizing and modern formats. Use the Image component and mark the hero image for preloading, with the preload prop in Next.js 16 or priority in earlier versions.

5. Use next/font

It downloads fonts at build time and serves them from your own domain, which removes a connection to a third party and a render-blocking request.

6. Delay third-party scripts

Load analytics and chat widgets with next/script and a lazy strategy so they do not compete with your own code during the first load.

See how your site does

Free test with AI fixes written for your platform.

Test your Next.js app

More guides