Nine Ways to Speed Up Next.js Dev Builds and Production Bundles
Faster Next.js: use Turbopack, skip barrel files, split type checking, keep client components small, lazy-load heavy libraries and trim production bundles.
This article is published in English.
Next.js gives you routing, server rendering, API routes and image optimization on top of React with almost no setup, which is why it's such a common pick, AI-generated projects included. As a project grows, though, the same complaints appear. Builds drag, Hot Module Replacement lags, and even a one-line UI tweak feels slow. A ten-second compile in place of a one-second one adds up to hours every month, and waiting on an AI assistant to apply a change while the page recompiles is irritating on top of that.
Letting an AI assistant audit the project
With an AI code editor, you don't have to apply each tip by hand. Ask the assistant to compare the codebase against the practices below. A useful request tells it to check each practice, explain why it matters, estimate the effect on dev speed, build time or runtime, show the exact code change, and confirm everything against current official Next.js and React documentation. It should flag advice that has become outdated or deprecated and name the newer approach instead, and it shouldn't make speculative optimizations that the docs don't support or that don't fit the project.
Review whatever it generates before merging. Frameworks move fast, and what helped a year ago may be irrelevant now. Treat the assistant like an experienced reviewer, not an oracle. Official documentation and the needs of the specific app make the final call.
Nine habits that pay off
1. Run development on Turbopack
On recent Next.js versions, Turbopack is stable for local development. Turning it on is a flag:
next dev --turbopack
Where the older webpack-based dev server works through more of the project, Turbopack rebuilds only the modules that changed. On mid-sized and large projects, startup and HMR improve right away. Production builds still use the standard pipeline, so using it in development carries little risk.
2. Precompile heavy dependencies
Reprocessing rarely changing third-party packages on every startup is a major cause of slow starts. Material UI, Monaco Editor, Three.js, Chart.js and large icon sets are costly to handle each time the dev server boots. Next.js can optimize imports for named packages:
experimental: {
optimizePackageImports: [
"@mui/material",
"@mui/icons-material",
"lodash"
]
}
Also avoid pulling in a whole package when one utility will do. A smaller dependency graph compiles faster.
3. Skip barrel files
A single index.ts that re-exports every component makes imports look tidy, but it forces the compiler to walk many more files than necessary. This import goes through the barrel:
import { Button } from "@/components";
Importing from the component's own path is better:
import Button from "@/components/Button";
It's a minor edit that trims module resolution, particularly in larger apps.
4. Keep type checking out of the dev server
Many developers block their dev server on TypeScript checks that the editor already runs. Start the server and a TypeScript watcher as two separate processes:
next dev --turbopack
tsc --watch
The page refreshes instantly, and type errors still show up live.
5. Keep client components small
In the App Router, any file marked "use client" ends up in the browser bundle. Ask whether a component really needs client rendering. Static layouts, navigation, content pages and data fetching can often stay as Server Components, with Client Components saved for parts that truly need interactivity. That sends less JavaScript to the browser and also means fewer client modules to rebuild during development.
6. Load heavy libraries on demand
A dependency that isn't needed on first paint can wait. Editors, PDF viewers, maps, charting and visualization packages are good candidates for loading lazily, only when someone reaches them:
const Editor = dynamic(() => import("./Editor"), {
ssr: false
});
Both the initial bundle and dev rebuilds stay noticeably smaller.
7. Split big components
Giant page components slow everyone down. A page with hundreds of lines of JSX is better broken into smaller reusable pieces, which the compiler caches more easily, which are simpler to test and which rebuild faster when something changes. If a file is getting hard to navigate, that's usually the cue to split it.
8. Turn off unneeded services in development
Analytics, logging platforms, session replay, monitoring SDKs and marketing scripts matter in production and seldom help while building features. Start them only when running in production:
if (process.env.NODE_ENV === "production") {
initializeAnalytics();
initializePWA();
}
Less initialization means a cleaner local startup and no outside network calls while developing.
9. Tune the production build too
Dev speed is half the picture. Use the Next.js Image component instead of raw image tags, cache wherever possible, compress assets and rely on Server Components to cut shipped JavaScript. Check the bundle every so often with the bundle analyzer, so surprisingly large dependencies are caught early. Many small improvements along the way usually beat one big optimization at the end.
Where to start
The aim is to learn where time is actually going, whether in development, in the build or at runtime. Begin with fundamentals: a tidy dependency graph, thoughtful code splitting, minimal client-side JavaScript and the tools Next.js already provides. Measure what changes, iterate, and revisit the architecture as the app grows.
Next.js keeps evolving, and recommendations shift with each release. Whether the changes come from you or from an AI assistant, check them against the latest official Next.js and React docs first. The best optimization is the one that's correct for the version you're building on today, not the one that was popular last year.