How do I get W3 Total Cache not to cache sidebars?

At the moment I run PHP code in my side bars. Even though I have the following

header("Pragma: no-cache");
header("cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past

It still appears to serve cached content.

Related posts

Leave a Reply

3 comments

  1. You’ll probably need to find a solution that loads this content via JavaScript…unfortunately. That’s the only way around this issue that I’ve found. I’ve solved it by building a container and a separate (non-cached) PHP file that gets whatever content you’d want in the sidebar.

    Then…use jQuery’s “.load” to pull the PHP content into that container on the cached page. Works well for me here: http://www.missouladowntown.com.

    Hope that helps.

  2. Those headers which you’ve put in your question apply to the entire page, you can’t set them just for a sidebar as the page has already been loaded at this point.

    You could do as Ross said and alternatively load the sidebar fragment after the page has loaded via ajax, or you could use an iframe to load in. You could then use the headers to set the expiry of the sidebar content separately to the main page.