"Ship less JavaScript" is advice nobody argues with and almost nobody acts on, because the first question — less of what? — has no obvious answer. The bundle is a number in the build output and a folder of hashed filenames, and neither tells you which import to go and delete.
This is how to turn that number into a short list of names.
Start with the build output
Before installing anything, run a production build and read the route table.
Route (app) Size First Load JS
┌ ○ / 1.2 kB 112 kB
├ ○ /blog 1.8 kB 113 kB
├ ● /blog/[slug] 4.1 kB 148 kB
└ ○ /about 940 B 111 kB
+ First Load JS shared by all 106 kBTwo columns, and the second is the one that matters. Size is the code unique to that route. First Load JS is everything the browser must download and execute before the route is interactive, meaning the route's own code plus the shared chunk.
The shared line at the bottom is the quiet one, and the one I check first. It is paid on every route, so a heavy dependency imported in a root layout costs far more than the same dependency imported in a single page. If that number is large, no amount of per-page work will rescue you.
So the table asks the question for you: one fat route, or a fat baseline?
Then open the chunk
Once you know which one to look inside, @next/bundle-analyzer shows what is in it.
import withBundleAnalyzer from "@next/bundle-analyzer";
const analyze = withBundleAnalyzer({ enabled: process.env.ANALYZE === "true" });
export default analyze({
// your config
});ANALYZE=true npm run buildIt opens a treemap where area is size. The habit worth building is ignoring everything small. In every bundle I have opened, three or four blocks explain most of the weight and the remaining hundred are noise that will eat an afternoon if you let them. Name the big blocks, then go find the import that pulled each one in.
The four imports that usually explain it
Date libraries come first. A full-featured one with locale data can outweigh your application code. If you format a handful of dates, Intl.DateTimeFormat is in the browser already and costs nothing:
const formatted = new Intl.DateTimeFormat("en-IN", {
day: "numeric", month: "short", year: "numeric",
}).format(new Date(iso));Icon packs imported from the index are next. import { ChevronDown } from "some-icons" reads like one icon and can resolve to a module re-exporting thousands of them. Import the specific path, or list the package in optimizePackageImports:
export default {
experimental: { optimizePackageImports: ["some-icons", "some-ui-kit"] },
};Utility libraries pulled in for two functions are the third. Importing a whole package to call debounce and groupBy is a trade most teams would decline if the cost were visible on the invoice. Import the two from their own paths, or write them, since both are under ten lines.
And a heavy component rendered rarely is the fourth. A chart library, a rich-text editor, a map. These belong behind a dynamic import so they load when the thing is actually used:
import dynamic from "next/dynamic";
const Chart = dynamic(() => import("./Chart"), {
ssr: false,
loading: () => <div className="h-64" />, // reserve the space, or you trade bytes for layout shift
});One constraint on that snippet: ssr: false is only allowed in a Client Component, so the dynamic import lives in the interactive part of the tree rather than in the server page that renders it.
That loading placeholder is load-bearing, not decoration. Swapping a lazily-loaded component into a page with no reserved height is exactly how a bundle fix turns into a Cumulative Layout Shift problem, and then you have traded one metric for another.
The structural lever: where the code runs
Everything above is tuning. The real decision in the App Router is what runs on the server at all.
A Server Component's code never reaches the browser. The markdown parser, the syntax highlighter, the database client, the date formatting: all of it executes during the render and what ships is HTML. The moment a component is marked "use client", it and everything it imports become part of the client bundle.
That makes "use client" the most expensive line in a Next.js codebase, and the usual mistake is putting it too high up the tree.
// Costly: the whole page, its imports and its children become client code
"use client";
export default function Page() { /* … */ }// Better: the page stays on the server, and one small leaf is interactive
export default function Page() {
return (
<article>
<Prose html={html} /> {/* server: parser never ships */}
<CopyButton text={code} /> {/* "use client" lives in here */}
</article>
);
}Push the boundary down to the leaves that genuinely need state, effects or event handlers, and the rest of the tree, along with every library it touches, stays on the server. It is the same boundary discipline that keeps the hero out of hydration's way.
Confirm what you shipped
A bundle fix that is not verified has a habit of coming back.
Re-read the route table after building again and compare First Load JS per route. If the shared line did not move, the dependency is still somewhere shared, however many dynamic imports you added on top.
Then read the network panel on a cold load. Throttle to a slow connection, disable cache, and watch what JavaScript is requested before the page becomes interactive. The analyzer shows what exists. The network panel shows what the browser actually fetched for this route, which is the only one of the two numbers a visitor experiences.
Next's own defaults also shift between versions, and bundling behaviour and image handling both changed in ways that are easy to miss. The Next.js 16 notes collect the ones that caught me. A size change you did not cause is usually one of those.
Where to start, and where to stop
Bundle work goes wrong when it starts with the folder of hashed filenames. Start with the table. Find the route, find the chunk, find the three names that explain it.
In practice the fix is almost always one of four things. A date library replaced by Intl. An index import narrowed to a path. A rarely-used component moved behind dynamic. A "use client" pushed further down the tree.
Everything after that is rounding, and rounding is not worth a sprint.