Next.js · Senior · Question 11 of 75
Why does a CSP with a nonce make pages dynamic?
- ✓Correct answer: The nonce is unique per response, so the HTML can't be prerendered
- 2Browsers and CDNs don't cache pages that have a CSP header
- 3Nonces are supported only with client-side rendering
Explanation
Next.js reads the nonce from a request header (generated by proxy) and adds it to its scripts. Static HTML with a fixed nonce makes no sense. An alternative that keeps static rendering is a hash-based CSP or looser policies.