Next.js 16.5
导读
Next.js 团队发布了 Next.js 16.5,该版本通过 Turbopack 加快了生产构建,并让未变更的远程缓存在多次部署之间沿用,同时改进了 bundle 分析和 Partial Prefetching。据其在 Vercel 仪表盘上的基准测试,冷编译速度约提升 4.2 倍、内存占用减少 38%,磁盘缓存缩小 14%。标记为 'use cache: remote' 的函数在代码和依赖未变时可读取上一次部署的缓存条目。
正在把原文翻译成中文,长文需要一两分钟;先显示原文。
2 Dec 2026
Next.js Team
Next.js 16.5 is now available!
This release speeds up production builds with Turbopack, lets unchanged remote caches carry over across deployments, and adds improvements to bundle analysis and Partial Prefetching.
Here's what's new in 16.5:
- Faster Turbopack builds. In our benchmarks on Vercel's dashboard, cold compilation is ~4.2× faster and uses 38% less memory, and the on-disk cache is 14% smaller.
- Cross-deployment caching. Functions marked with
'use cache: remote'can read cached entries from a previous deployment when their code and dependencies haven't changed. - Bundle reports can now be generated during builds. Running
next build --analyzegenerates a bundle report directly from your production build's compilation step. - Automatic disk cache cleanup. Turbopack's garbage collector is now enabled by default.
- Per-link navigation prefetching. Setting
prefetch="navigation"lets an individual<Link>prefetch cached content thatnavigation()would otherwise defer until click. - Automatically upgrade your app in CI.
next upgrade --cisets up a GitHub Actions workflow where a coding agent upgrades your app and opens a pull request when a new release ships. - Safe mode for image optimization. A new experimental
next/imageoptimization implementation that uses sandboxing and memory-safe image decoders to reduce security risks associated with processing untrusted images.
Next.js 16.5 also introduces experimental native Route Handler support, starting with Go Route Handlers, so you can write a route.go file alongside your TypeScript routes.
Upgrade today with a coding agent, or install next@latest directly:
# Upgrade with a coding agent
npx next@canary upgrade --agent=latest
# Or upgrade manually
npm install next@latest
Faster Turbopack builds
The rise of agentic development has brought new challenges to build tools. Instead of one developer using their machine to work on one or two projects at a time, today that same developer may use a fleet of agents to run dozens of Next.js servers simultaneously on that same computer.
To support these new workflows, we've focused on improving Turbopack's build performance in a few key areas:
- Better utilization of all available CPU cores during builds
- Ensuring applications can scale to thousands of routes
- Reducing memory and disk space overheads to keep applications inside build container limits
To measure the impact of this work, we benchmarked compilation of Vercel's dashboard on a 30-core, 60 GB build machine.
Compile times on a cold start in 16.5 were four times as fast as they were in 16.4.6, which is especially beneficial for agents as they tend to work from a fresh checkout.
Cold cache, ~4.2× faster
16.4.6183s
16.5.044s
Warm cache, ~2.7× faster
16.4.612.0s
16.5.04.4s
Compile times of vercel.com.
Full production builds also benefited from these changes, with cold builds cutting their time in half:
Cold cache, ~2.0× faster
16.4.6325s
16.5.0159s
Warm cache, ~1.3× faster
16.4.6134s
16.5.0107s
Full production build times of vercel.com.
We also optimized Turbopack to use memory and disk space more efficiently:
Peak memory while compiling, cold cache, 38% less
16.4.624.1 GB
16.5.015.0 GB
Peak memory while compiling, warm cache, 28% less
16.4.68.2 GB
16.5.05.9 GB
Cache size on disk, 14% smaller
16.4.62.96 GB
16.5.02.56 GB
Memory and disk usage during builds of vercel.com.
Across five other Vercel apps we benchmarked, including nextjs.org, we saw reductions in peak memory by 6%-27% and disk cache sizes by up to 23%.
Cross-deployment caching
Previously, deploying a new version of your app would effectively reset the cache for every function that used 'use cache: remote'. This is because Next.js included the build or deployment ID in each function's cache key, to prevent cache entries from returning stale data in the event their code or dependencies changed.
For example, say you had a function like getProduct:
import { db } from "@/lib/db";
export async function getProduct(id: string) {
"use cache: remote";
return db.product.findUnique({ where: { id } });
}
Even if you edited an unrelated page and didn't change getProduct at all, redeploying your app meant that this function would have to query the database again the first time it executed in this new deployment.
Next.js 16.5 fixes this. Functions using 'use cache: remote' now have the ability to reuse their entries across deployments.
In 16.5, Turbopack scans your cached functions and their dependencies to generate each cache key from the function itself, the code it depends on, and the environment values it reads.
If you make an unrelated change and redeploy, and getProduct's code and dependencies haven't changed, the new deployment can reuse the cache entries from the previous one.
Entries still expire and revalidate as usual. Next.js also stops reusing an entry if any of the function's transitive imports or any of the environment values it reads change.
When Turbopack can't determine everything a function depends on, Next.js falls back to a deployment-specific key, just as before. Notably, this happens when accessing process.env in a dynamic way, such as process.env[variable] or parseConfig(process.env).
Learn more about the use cache: remote directive and using it with Vercel's Runtime Cache.
Bundle reports can now be generated during builds
The Next.js Bundle Analyzer helps you optimize your application's bundle sizes by making it easy to track down large dependencies.
Previously, you could generate a bundle report to disk by running
npx next analyze --output
This writes the report to .next/diagnostics/analyze, and can be used during builds on CI so changes to your bundles can be tracked over time.
In Next.js 16.5, you can use the new --analyze option to generate a report during your normal production builds:
npx next build --analyze
This lets you avoid running a second compilation of your app, and also guarantees that the JavaScript, CSS, and source maps you see in the bundle report match your production deployment exactly.
Learn how to trace a module's imports in the Bundle Analyzer.
Automatic disk cache cleanup
Next.js 16.4 introduced a new experimental garbage collector that cleaned up unused compilation work during long dev sessions via the turbopackGc flag.
In 16.5, we're enabling this feature by default for all apps.
With garbage collection enabled, Turbopack's cache only grows with the size of your application, rather than with the number of changes to it, keeping updates fast during rebuilds.
Learn more about configuring Turbopack's cache cleanup.
Per-link navigation prefetching
In Next.js 16.4, we released the navigation() API. You can use this API to exclude content from a prefetch, letting you avoiding rendering secondary content until an actual navigation takes place.
The example from the 16.4 blog post showed using it to exclude an email's replies from being rendered during the Inbox's prefetches:
import { navigation } from 'next/cache';
async function Message({ id }) {
const message = await getMessage(id);
return (
<>
<p>{message.subject}</p>
<div>{message.body}</div>
<Suspense fallback={<Spinner />}>
<Thread id={id} />
</Suspense>
</>
);
}
async function Thread({ id }) {
await navigation(); // Exclude Threads from being prefetched
const thread = await getThread(id);
return (
<>
{thread.map((message) => (
<div key={message.id}>{message.body}</div>
))}
</>
);
}
This let the Inbox render prefetched links, without having to fully load every single message's thread:
<nav>
{messages.map((message) => (
<Link
href={`/message/${message.id}`}
key={message.id}
prefetch
>
{message.subject}
</Link>
))}
</nav>
But sometimes you might have a specific link that you know the user is very likely to click next. In that case, you may want that link to more aggressively prefetch all the possible cached content from the upcoming page, even content that's behind an await navigation().
In the email app example, you might have a single "Next unread" button that is a good candidate for prefetching both the message and the complete thread, as it doesn't appear in a long list of links like the rest of the Inbox.
In Next.js 16.5, you can use <Link prefetch='navigation'> to prefetch all cached content for a target page, even content that would otherwise be deferred by await navigation():
<Link href="/message/42" prefetch="navigation">
Next unread
</Link>
Once "Next unread" enters the viewport, Next.js prefetches the full thread, so all the content is instantly ready by the time the user clicks.
Learn more about prefetching deferred content for a likely navigation.
Automatically upgrade your app in CI
next upgrade --agent lets a coding agent upgrade your app on demand. In 16.5, you can also run that upgrade in CI on a schedule with GitHub Actions:
npx next@canary upgrade --ci
The command asks which upgrades to check for (security advisories only, or every new stable release) and which hosted agent to use: Codex or Claude Code, with an OpenAI or Anthropic API key, a Vercel AI Gateway key, or a Claude subscription. It then opens a pull request that adds the workflow and helps you store the credentials as repository secrets.
Once merged, the workflow checks for a new release every day. When one matches your policy, the agent upgrades the app and opens a pull request with the result for you to review.
You can also ask your coding agent to run next upgrade --ci for you; it picks sensible defaults and opens the setup pull request without prompting.
Learn more about running scheduled upgrades on GitHub.
Experimental features
Go Route Handlers
Next.js 16.5 introduces experimental native Route Handler support, starting with Go. You can add a route.go file anywhere in the App Router alongside your TypeScript routes, and Turbopack compiles it into a native executable served at that route path while the rest of your app stays in TypeScript.
To try a Go Route Handler, install Go 1.24 or later and enable goRoutes in a project using Turbopack:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
experimental: {
goRoutes: true,
},
};
export default nextConfig;
Then add a route.go file to handle GET /api/hello:
package route
import (
"fmt"
"net/http"
)
func GET(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello from Go!")
}
Run next dev and open /api/hello to see Hello from Go!. When you edit the handler, Turbopack recompiles it automatically.
To learn more, read our latest post on Native Languages in Next.js.
Safe mode for image optimization
As we recently discussed in our blog post about securing Next.js, we've been working on an alternative implementation of image optimization for Next.js.
This new image optimization mode uses a combination of memory-safe image decoders, process isolation, and Linux seccomp sandboxing to reduce the risks associated with processing untrusted images.
Try it out today by enabling experimental.imgOptSafeMode in your Next.js config:
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
experimental: {
imgOptSafeMode: true,
},
};
export default nextConfig;
This option may be ignored in production if your deployment platform provides its own image optimization service, such as on Vercel. In these cases, similar protections and mitigations are already provided by the deployment platform.
Feedback and community
We hope you're excited to try out Next.js 16.5!
Let your agent upgrade your app with our CLI command:
npx next@canary upgrade --agent=latest
or upgrade yourself:
npm install next@latest
And share your feedback to help shape the future of Next.js:
Contributors
Next.js is the result of the combined work of thousands of individual developers. This release was brought to you by:
Huge thanks to @unstubbable, @eps1lon, @gaojude, @DavidIlie, @styfle, @deveshasawa28, @kakadiadarpan, @adityareddy-dev, @abhayymishraa, @blz-ea, @franpeza, @awss1i, @JannikZed, @dxdc, @mugi-uno, @leejpsd, @sabrinaluo, @kxrn-gupta, @yousefdawood7, @tobiaslins, @Aryan9891, @koreahghg, @zydo, @digasic, @huozhi, @arnaud-coral, @skrabe, @namtran1812, @chadhietala, @smaeda-ks, @vctqs1, @fireairforce, @shootaroo, @linyiru, @fediev, @robsimmons, @Rezakarimzadeh98, @codeandcore, @ShakilUrRehman21, @swarnava, @sleitor, @0badran, @DominikKoniarz, @zhengdaodeguL, @hyungjikim, and @ali-vercel for helping!
出处
- S 官方Next.js Blog · RSS阅读原文 ↗
生成时使用了正文节选。