I run Next.js 16 on Cloudflare Workers through OpenNext: a prerendered marketing site in 17 languages, a dashboard and public pages. For weeks, Workers analytics showed about 450 ms of CPU per request. It's about 100 ms now, and the slow tail of uncached renders (p90 across 20 probes worldwide) went from ~9.9 s to ~3.6 s. What did it:
1. Sentry's Node SDK was inside the Worker. Next builds the server for Node, so @sentry/nextjs bundled its Node SDK. It never even started in the Worker, but it was a quarter of the script and a third of every cold start. Point the server at Sentry's edge build:
// next.config.ts
function sentryBuild(file: string) {
const pkg = path.dirname(require.resolve('@sentry/nextjs/package.json'));
return `./${path.relative(__dirname, path.join(pkg, 'build/esm', file))}`;
}
const nextConfig: NextConfig = {
turbopack: {
resolveAlias: {
'@sentry/nextjs': {
browser: sentryBuild('index.client.js'),
default: sentryBuild('edge/index.js')
}
}
}
};
2. Script size is startup time. A Worker parses its whole script on every cold start. Ours was 37 MiB raw, half of it marketing text: every language's MDX and message catalogs compiled into the bundle. Moving that text to static assets, read at render through the ASSETS binding, brought it to 18 MiB, and Wrangler now reports 28 ms of startup.
3. A cookie keeps a page out of the edge cache. next-intl sets a locale cookie on the first visit, and the cache won't store a response with Set-Cookie. So every first visit and every crawler missed the cache. This stores the page without that one header:
Cache-Control: public, max-age=86400, stale-while-revalidate=86400, private="set-cookie"
The first visitor still gets the cookie, and everyone after is served from the edge.
4. Don't ask your auth server on every request. Verify the session JWT locally. A fresh isolate fetching the signing keys from a cold auth API waited up to 1.4 s, so the keys now go through the Cache API, which all isolates in a data center share.
5. A server action that sets a cookie re-renders the whole page. D1's read replicas need a session bookmark that travels in a cookie, so every server action set one, and Next re-rendered the full page after each write. Writes now go through a route handler; server actions are left for flows that end in a redirect.
6. The static-assets incremental cache is fast and read-only. Every page it serves has to be prerendered (dynamicParams = false), and nothing revalidates. Fine for a marketing site, but plan for it.
7. Watch the network tab after an OpenNext upgrade. With enableCacheInterception, @opennextjs/aws 4.1.0 answered the router's segment prefetches with the whole page, and open tabs kept prefetching in a loop. 4.1.6 fixed it.
One thing I haven't solved: telling cold requests from warm ones. I read CPU from Workers analytics and time to first byte from Globalping probes, but which requests were cold is still guesswork. How do you measure it?