Turbopack’s chunking speeds up page loads and enables sharing code across pages. We shipped new experimental features to improve chunking in Next.js 16.3.
Open the network tab of this page and you’ll see a list of JavaScript files with seemingly random names:
Click on one of them, unminify it, and you’ll find something like this:
That's a chunk. Turbopack generates dozens of them for your Next.js app, holding your own code, the packages you depend on, and the runtime that wires it all together.
“Chunking” is the process of deciding which code goes into which chunk. There are a lot of ways to do chunking, each with their own tradeoffs.
Let's start with the simplest approach: one chunk containing all the JavaScript your app uses.
All 355 modules in one chunk, loaded on every page.
This is an excerpt. The full article is published by Next.js Blog.
Answers to common questions regarding this article's topic, architecture, and practical applications.
You may have noticed that we make a lot of assumptions about websites in our chunking algorithm. For example, the 2/3 weighting is a guess. It’s a reasonable default across many sites, but not necessarily the right one for any given site. If you know how people actually move through yours, you can tell us. In your next.config.js, you can now configure these under experimental.turbopackChunking:
General
Open the network tab of this page and you’ll see a list of JavaScript files with seemingly random names:
Definition / Understanding
Here’s a comparison between the versions of chunking we discussed. To generate the numbers for each, I visited nextjs.org with three different Turbopack chunking configurations: never merge, the defaults, and merge everything within each chunk group. On each version I ran the same series of navigations, measuring requests and client-side JavaScript downloaded. As you can see, chunking is a balancing act. On nextjs.org, defaults cut requests by mo
General
Two things limit how well chunking works. Merging is decided at build time, before anyone visits, so it can't react to what a browser already has cached. And the algorithm has to guess at how people move through your site, which is why single-page visits get weighted at 2/3. This summer, as part of my internship on the Turbopack team, I worked on both, along with trimming what ends up in the chunks in the first place.
General
Everything above is about how to group code. This last set of features is about shipping less of it in the first place. I worked on the following features to support this: