Dynamic rendering with inline script nonce
Answered
Spectacled bear posted this in #help-forum
Spectacled bearOP
I'm adding middleware to generate a nonce for inline scripts to my app. I'm following the instructions at https://nextjs.org/docs/app/building-your-application/configuring/content-security-policy
The instructions state "Every time a page is viewed, a fresh nonce should be generated. This means that you must use dynamic rendering to add nonces."
How do I ensure dynamic rendering?
Do I have to add the
I'm using app router.
The instructions state "Every time a page is viewed, a fresh nonce should be generated. This means that you must use dynamic rendering to add nonces."
How do I ensure dynamic rendering?
Do I have to add the
export const dynamic = "force-dynamic";
directive to every single page?I'm using app router.
Answered by Alfonsus Ardani
chec your buidl logs. depending on how you write it, some of them might already be dynamic. that way you dont need to put that in every single page.
but if you want to make sure then yeah.
but if you want to make sure then yeah.
2 Replies
@Spectacled bear I'm adding middleware to generate a nonce for inline scripts to my app. I'm following the instructions at https://nextjs.org/docs/app/building-your-application/configuring/content-security-policy
The instructions state "Every time a page is viewed, a fresh nonce should be generated. This means that you must use dynamic rendering to add nonces."
How do I ensure dynamic rendering?
Do I have to add the `export const dynamic = "force-dynamic";` directive to every single page?
I'm using app router.
chec your buidl logs. depending on how you write it, some of them might already be dynamic. that way you dont need to put that in every single page.
but if you want to make sure then yeah.
but if you want to make sure then yeah.
Answer
Spectacled bearOP
Thanks.