Following Google Lighthouse recommandations to get a faster response for my website, I'm using this trick to post-load fonts:
<link as="style"
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;600;700&display=swap"
onload="this.onload=null;this.rel='stylesheet'"
rel="preload">
But it fails because of my strict CSP rules, and I don't know how to add a sha384 hash for this "onload" attribute :/
I tried to get the onload
content hash like this:
echo "this.onload=null;this.rel='stylesheet'" | openssl dgst | openssl enc -base64 -A
Output: npWtxZLLH7z2/zORM47igyJ5eTYuOl9qxzn4A632S7yMmMKBDHhL5ZHC6eBSxc/C
Then I add it on CSP SRI list, and refresh, but it fails with:
Refused to execute inline event handler because it violates the following Content Security Policy directive: "script-src 'strict-dynamic' '[...list of other SRI hashes...]' sha384-npWtxZLLH7z2/zORM47igyJ5eTYuOl9qxzn4A632S7yMmMKBDHhL5ZHC6eBSxc/C 'unsafe-inline' http: https:". Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
How to permit this inline "onload" little script without authorize all inline scripts ? Why my SRI doesn't work when I add it ? :(
Thanks !