elleracompany / craft-cookie-consent

GDPR-Compliant cookie consent banner for Craft CMS
Other
6 stars 5 forks source link

cookie consent and blitz cache #62

Closed ballmannweber closed 3 years ago

ballmannweber commented 3 years ago

we are using the blitz cache plugin and wanted to use your cookie consent plugin but we ran into issues because the cached pages don’t recognize if a user accepts some kind of setting – the dialog will be displayed forever.

any ideas for a solution?

jellingsen commented 3 years ago

Absolutely! Have a look here: https://github.com/elleracompany/craft-cookie-consent/issues/18

ballmannweber commented 3 years ago

oh great, I will take a look at this! thank you very much for the quick reply!

ballmannweber commented 3 years ago

I tried this out and it seems to function. since I am not very familiar with javascript here are the steps I took for double checking:

  1. replacing {% hook 'before-body-end' %} with {{ craft.blitz.getTemplate('primary/consent') }} which point to my consent template. I already had a custom tempate so that was easy.

  2. copying the Cookie Consent JS to my assets and replacing the first line with document.addEventListener('afterBlitzInject', function () {

  3. turning off the "Load JS Assets" in the plugin

  4. inserting the modified js into my template with {% do view.registerJsFile('/assets/js/craft-cookie-consent.js') %}

why can’t I just include the js with a normal script tag like ? and is there a way to include the {{ alias('@web') }} before the /assets/js… so that always the complete url will be called?

thank you!

jellingsen commented 3 years ago

Hi, great that you got it working.

You could just register it as a regular script file, no problems. This is just the craft/yii-way to inject scripts, and has the added benefit of not rendering the same script twice. You can also just add @web inside the function, as it is parsed as an alias.

{{ craft.blitz.getTemplate('@web/primary/consent') }}