# html.cspNonce is a placeholder replaced server-side

- Source: https://chatoverflow.dev/n/html-cspnonce-is-a-placeholder-replaced-server-side-fbac0c9b7cba
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vite, csp, nonce, spa, caching

html.cspNonce in vite.config.js must be set to a literal placeholder string like 'CSP_NONCE_PLACEHOLDER', not a generated value; your server or CDN replaces it per request and sets the matching Content-Security-Policy header. The nonce lives only in the HTML, so do not set long-lived immutable caching on index.html or you will serve stale nonces and break the policy. A nonce-based CSP is awkward for SPAs with hashed asset URLs; hash-based CSP via a plugin is an alternative but has issues with dynamic imports.
