4

I use w3 total cache on a site I run which also now has to display a small popup at the bottom of the page to mention that the site uses cookies (thanks EU). The idea is that this only appears the first time the user sees the page, a cookie is then set to make sure the site doesn't show this user the popup again.

However W3 will often cache a version of the site with this popup visible meaning the popup is shown regardless of the cookie existing or not.

The popup is drawn with a <div> at the bottom of each page and it is only drawn if the cookie is set. Essentially the question is, how can I exclude W3 cache from always showing this? Is this even possible, or is there an alternative to how this popup is shown that gets around this issue?

Thanks.

1 Answer 1

4

In W3TC you can specify files or cookies that are ignored and not cached.

Exclude Files from Cache
To do this go to WordPress Admin > Performance > Page Cache

In the screenshot ... you will see I've added custom sidebars from a Twenty-Eleven theme. These are excluded from being cached.

W3TC excluded files

You can also specify your custom cookie to not be cached ...

Browser Cache Settings
BUT also check your Browser Cache settings as you'll probably want to reduce these from 1 year to 1 month or week or day.

3
  • The problem with this is that every page potentially shows the popup and therefore uses the cookie. This would remove all pages from the cache making it pretty redundant. I'm going to have to rethink this mechanism, maybe draw the popup using javascript so that W3 won't see it when creating the cache... assuming that W3 doesn't create the cache after any DOM changes. Thanks for the help anyway
    – artparks
    Aug 15, 2012 at 13:31
  • 2
    Hi @artparks the code for your popup could be put in its own file like /includes/cookie_warning.php it would then be just this one file to exclude + the sidebar or header.php
    – Damien
    Aug 15, 2012 at 15:11
  • 1
    In 2018, the values in the "Never cache the following pages" field are checked against $_SERVER['REQUEST_URI'] so adding separate PHP templates won't work. Jun 1, 2018 at 4:39

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