Support » Plugin: Cookie Notice & Consent » Cookie consent briefly pops up on page after acceptance

  • Resolved TomHayes

    (@tomhayes)


    Hi,

    I’ve noticed on my site, sometimes (happens more on mobile than on desktop) after accepting the cookie consent and navigating to a new page, the popup will display for a brief period before disappearing again. On a slow connection this can happen for upwards of a second.

    Is there anything I can do to stop this from happening? My first thought was to use some JS to delay the display of the popup, giving it time to realise it was already accepted, but adding display:”none then replacing it with display:block after a timeout seems to stop the popup from being hidden afterwards, which is obviously not ideal.

    Thanks!

    • This topic was modified 2 months ago by TomHayes.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author christophrado

    (@christophrado)

    Hey! I see you have a cache plugin active on that site. This might cause a wrong CSS class to be present even when the consent has been set.

    Here’s what happens: On the PHP side, the cookie notice gets printed with either cookie-notice-consent--hidden or cookie-notice-consent--visible as a class, based on the cookie status. The JS then additionally checks for the presence of the status cookie and hides or shows the notice (by setting the proper class).

    With a cache in place, the PHP (or rather static HTML) likely always has the cookie-notice-consent--visible class (the cache gets generated without a cookie consent set), even after the user saved his choice. The JS then later properly hides it. That causes the short flash.

    I did some improvements for cache handling in an earlier version, but we might have to do some work on this.

    One idea would be to always hide the notice on the PHP side if a cache is active, and let the JS do the work. That would show the notice with a slight delay – as soon as the JS gets executed. But that might be better than a second flash of the notice the user just interacted with.

    I’ll have to do some tests on this, but I guess such a change would make sense.

    Let me know if this makes sense to you.

    Thread Starter TomHayes

    (@tomhayes)

    Hey, thanks for the in depth reply!

    That does totally make sense, and I can see why the cache would make a difference – the only thing I am unsure about is how I can actually implement this! How would I go about making sure the cookie notice is rendered with the cookie-notice-consent--hidden class by PHP?the static HTML created by the cache? A slight delay before the notice is shown would definitely be preferable to the cookie policy flashing up after previously be accepted I think!

    Thanks again!

    Plugin Author christophrado

    (@christophrado)

    If you’re okay with editing plugin files, you could try swapping line 53 of class-cnc-front.php (within the includes folder) for this:

    <div id="cookie-notice-consent" role="banner" class="cookie-notice-consent cookie-notice-consent--hidden" aria-label="<?php _e( 'Cookie Notice & Consent', 'cookie-notice-consent' ) ?>">

    That would basically output the notice as hidden in the HTML at all times. JS would then be the only one responsible for showing the notice.

    Then try clearing the cache and run some tests.

    If this works better, I’d implement a similar cache-aware change with the next release.

    Thread Starter TomHayes

    (@tomhayes)

    Thanks a lot! That worked brilliantly 🙂 No issues noticed so far!

    Plugin Author christophrado

    (@christophrado)

    Great! I’ll push out an update with a cache-sensitive change for that later.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.