2

I run a website with inline javascript.

I created a security policy so javascript can run inline. Then Pagespeed insights shows this issue:

screenshot from pagespeed insights

When I read about CSP nonces and hashes, it means generating a unique value both in the HTTP header (where the policy is defined) and in the HTML.

The thing is, my HTML pages are generated with PHP once then saved as cached HTML files so they load faster on subsequent requests. but if I have to assign unique values to satisfy CSP and google, then I would need to break my cache every time.

How do I go about satisfying google here without destroying the cache?

1 Answer 1

0

Try using strict-dynamic in your security policy.

With it, you can dynamically load resources while maintaining security, and you can do without unique nons for each request.

You can read more about it here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.