→
IS
← All notes
#csp#nextjs#performance#caching

A CSP nonce turns off static rendering in Next.js

A strict per-request CSP nonce cost this site its static generation entirely. I read the nonce in the root layout via headers(), and that is a dynamic API: Next.js switches every page under that layout to per-request rendering, even when they have generateStaticParams.

// app/[locale]/layout.tsx
const nonce = (await headers()).get('x-nonce'); // the whole route subtree is now dynamic

You can see it right in the response: cache-control: private, no-cache, no-store and x-vercel-cache: MISS on a page without a single dynamic line. It is a trade-off, not a bug: a nonce must be unique per response, so the HTML cannot sit in a CDN cache. If speed matters more, look at a hash-based CSP (the experimental sri option in Next.js) or keep the nonce only on pages that take user input.