@ -68,8 +68,11 @@ All data returned from a `hydratable` function must be serializable. But this do
`hydratable` adds an inline `<script>` block to the `head` returned from `render`. If you're using [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) (CSP), this script will likely fail to run. You can provide a `nonce` to `render`:
`hydratable` adds an inline `<script>` block to the `head` returned from `render`. If you're using [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) (CSP), this script will likely fail to run. You can provide a `nonce` to `render`:
This will add the `nonce` to the script block, on the assumption that you will later add the same nonce to the CSP header of the document that contains it:
This will add the `nonce` to the script block, on the assumption that you will later add the same nonce to the CSP header of the document that contains it:
```js
```js
/// file: server.js
let response = new Response();
let nonce = 'xyz123';
// ---cut---
response.headers.set(
response.headers.set(
'Content-Security-Policy',
'Content-Security-Policy',
`script-src 'nonce-${nonce}'`
`script-src 'nonce-${nonce}'`
@ -91,7 +98,10 @@ It's essential that a `nonce` — which, British slang definition aside, means '
If instead you are generating static HTML ahead of time, you must use hashes instead:
If instead you are generating static HTML ahead of time, you must use hashes instead: