Shiba

Adventures in WordPress

  • — Home —
  • Dog
  • Art
  • Contact
  • WordPress Articles
    • WP Plugins
    • WP Programming
    • WP Admin Panels
    • WP Theme Design
    • WP How-To
    • WP Theme Images
You are here: Home / WordPress Plugin / W3 Total Cache – Cookie Is Rejected

W3 Total Cache – Cookie Is Rejected

Tweet

by ShibaShake 8 Comments

Recently, I switched over to W3 Total Cache. Reasons for the switch –

  • There have been a lot of great reviews and raves about W3 Total Cache.
  • W3 Total Cache offers a very comprehensive caching solution.
  • I was having caching issues on my multi-site setup.

In general, I am very happy with the results. There is a bit of a learning curve initially, but W3 Total Cache is well worth the effort. A BIG thanks to Frederick Townes for creating such an awesome plugin.

This article describes some common W3 Total Cache issues and how to fix them.

1. W3 Total Cache – Cookie Is Rejected

This is a common issue that arises whenever a user makes a comment on your blog. Making a comment causes a cookie to be set, and this disables caching for that user until the cookie is cleared or expired.

Here is an explanation by Frederick Townes.

In WordPress 3.0, the default comment cookie expiration time is 30,000,000 seconds which is about 8333 hours or 347 days. That is a long expiration time.

Unless the user manually clears his browser cookies, he will not get to enjoy the super caching capabilities on your site for about a whole year.

A simple way to fix this is to use the comment_cookie_lifetime filter which will only get applied for non-logged in users.

// Add filter to the init function of your theme functions.php file
add_filter('comment_cookie_lifetime', 'my_comment_cookie_lifetime');	
	
function my_comment_cookie_lifetime($lifetime) {
	return 10;
}

The code above shortens the comment cookie expiration time to 10 seconds. After 10 seconds, caching will be re-enabled for the user. I am just using 10 seconds as an example. You may set the expiration time to whatever works best for your environment.

You can test this by turning on Page Cache debugging in the main Performance >> General Settings screen.

Turn on Page Cache debugging in Performance >> General Settings.
”Turn

2. W3 Total Cache – URL Redirect Issues

If you have any rewrite rules in your .htaccess file, for example to remap your domain from www.site.com to site.com or vice versa, then make sure to put those rewrite rules before the W3 Total Cache rules.

For example –

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.site.com$ [NC]
RewriteRule ^(.*)$ http://site.com/$1 [R=301,L]

# BEGIN W3TC Page Cache
<IfModule mod_rewrite.c>
...

Here is a discussion of the redirect issue and the fix.

3. W3 Total Cache – Duration of Page Cache Files

If you want to change how long your pages are cached, it is not sufficient to just change the garbage collection interval in the Page Cache screen.

W3 Total Cache - Changing the file expiration time of the files in your Page Cache.
W3 Total Cache - Changing the file expiration time of the files in your Page Cache.

As stated in the notes section at the bottom of the Page Cache screen –

The TTL of page cache files is set via the “Expires header lifetime” field in the “HTML” section on Browser Cache Settings tab.

TTL = time to live.

Changing your Page Cache duration also requires a change in the Browser Cache screen.
Changing your Page Cache duration also requires a change in the Browser Cache screen.

4. W3 Total Cache – WordPress Multi-Site Settings

It is important to note that some W3 Cache settings affect the local .htaccess file (i.e., the .htaccess file on the main directory of your WordPress installation), while others affect the .htaccess file of your domain.

Many Browser Cache settings (e.g., those pertaining to header expiration) for example, change your domain .htaccess file. Page Cache settings on the other hand make changes to the .htaccess file that is local to your WordPress installation.

In WordPress multi-site (with sub-directories), several different blogs share the same local .htaccess file. As a result, certain W3 Cache Settings have to be identical for all of your blogs. In particular, I make the Page Cache and Browser Cache settings identical for all of my multi-site blogs. Otherwise, I get an error saying that Page Enhanced mode is disabled.

Here is a thread discussing this issue in detail.

Note – I also make header expiration settings in the Browser Cache screen identical for ALL blogs in my domain because that affects the main domain .htaccess file.

W3 Total Cache Is Awesome!

The purpose of this article is to summarize some of the things I learned while setting up W3 Total Cache.

Some time and effort is needed initially, but the rewards from the plugin are great. Make sure to get comfortable with the plugin on a test site first before installing it on your main site.

Related Articles

WordPress Comments Plugin - Cache and Customize Your Gravatars

Shiba Gravatar is now called Shiba Comments because we are broadening the plugin to include other comment related capabilities. The Shiba Comments Plugin allows you to - Cache gravatar images locally on your server as well as use your own set of gravatar images. Move comments between posts. Parent a comment to any other comment. Note - make sure not to create comment loops while doing this. Change the comment IP. [Most recent Shiba Comments Plugin updates] December, 2015 Tested [...]

Shiba Gravatar Plugin 1.4

The Shiba Gravatar Plugin allows you to cache gravatar images locally on your server as well as use your own set of gravatar images. This release updates the plugin for WordPress 3.1. We also expanded the plugin so that in addition to custom gravatar images, it will now cache generated (e.g. monster, identicon, wavatar) and non-generated (mystery man, blank, default logo) WordPress gravatar images. Here is a detailed description of the Shiba Gravatar Plugin. 1. Set Gravatar Settings [...]

Shiba Gravatar Plugin 1.3

The Shiba Gravatar Plugin allows you to cache gravatar images locally on your server as well as use your own set of gravatar images. In this release, we significantly streamlined the process for loading your own custom gravatars. This was based on Lanes excellent feature suggestion of tying the custom gravatar system to WordPress galleries. In particular, you may now tell the plugin to assign custom gravatars based on the images associated with your WordPress post, page, or gallery (if you [...]

Comments

  1. Gryzli says

    August 8, 2017 at 8:05 am

    Hi,
    Do you know if there are any pre-excluded cookies by default from W3TC caching ?

    Reply
  2. Julia Br says

    October 16, 2012 at 1:45 am

    Thanks a lot for this article, and for others… You helped me a lot.

    Reply
  3. David Goodwin says

    May 1, 2012 at 1:34 am

    Hi – Thanks for the cookie rejection note – much appreciated 🙂

    David.

    Reply
  4. Ben Zittlau says

    April 10, 2012 at 10:37 am

    Thanks for the number 3 point. I was suspicious that the garbage collection interval wasn’t actually going to expire my pages based on the description, but I didn’t relate the comment at the bottom to that point.

    Reply
  5. Stephen says

    February 3, 2012 at 6:46 pm

    super useful. I’m having consistent cookie rejected issues, it’s a pain. And while it says gzip is enables I don’t actually see any compression. Any ideas?

    Reply
  6. Bill says

    December 23, 2010 at 9:48 am

    You have an extra ) in your code for the “cookie is rejected” issue.

    The add_filter command should be:

    add_filter(‘comment_cookie_lifetime’, ‘my_comment_cookie_lifetime’);

    Reply
    • ShibaShake says

      December 23, 2010 at 8:31 pm

      Thanks Bill! I have fixed that in the article. Merry Christmas.

      Reply

Leave a Reply Cancel reply

Your email address will not be published.

Recent Posts

  • Screen-shot of mobile responsive Poll Daddy object, where text floats properly to the right of radio buttons.How to Make Poll Daddy Objects Mobile Responsive
  • Screen-shot of blog post with no page border (flowing design).Genesis Skins 1.5
  • Screen-shot of the media manager Create-Gallery screen, while doing a post search.Shiba Media Library 3.7
  • Screenshot of the Edit Gallery screen after we hit the Create Gallery button.How to Expand the WordPress Media Manager Interface
  • Blonde girl looking through and holding a circular picture frame.Shiba Gallery 4.3
  • Close-up of beautiful blonde holding a square picture frame.Google Authorship - Good or Bad for Search Traffic?
  • Shiba Widgets 2.0
  • Media Temple screenshot of editing my sub-domain DNS entry.Using CDN Cnames with w3tc and MultiSite
  • Shiba Skins WordPress ThemeShiba Skins WordPress Theme
  • How to add the Media Manager Menu to the Theme Preview InterfaceHow to Add the Media Manager Menu to the Theme Preview Interface

Recent Comments

  • Populate our Edit Gallery menu using a gallery shortcode.How to Add the WordPress 3.5 Media Manager Interface – Part 2 (29)
    • Janine
      - Still relevant in 2019.
  • Update custom inputs with the proper data using Javascript.Expand the WordPress Quick Edit Menu (57)
    • PhoenixJP
      - Thanks for this tutorial. Does someone knows if this still work with wordpress 5.03 and 5.1.
    • Francine Carrel
      - This is a very long time away from your original comment, but did you ever work it out? I am stuck on the exact same thing ...
  • WordPress Search Widget – How to Style It (55)
    • TelFiRE
      - How do you style the "X" that shows up when you start typing?
  • WordPress Excerpt – How to Style It (36)
    • James
      - Great post. I really need some help. I have set border lines around my excerpts on my blog page/post page. The problem is ...
  • Add Custom Taxonomy Tags to Your WordPress Permalinks (123)
    • Darshan Saroya
      - Update permalinks. Go to settings > permalink and just save it.
    • Darshan Saroya
      - I want to access two different types of taxonomies like city and room, how can I access it via wp permalink?
  • How to Selectively Load Plugins for Specific Pages (6)
    • cla
      - Perfect! But at first I was misled, I thought the path / wordpress-theme / was an your alias of / theme .. and nothing happened.. ...
    • Aeros
      - Hi, I have tried your way. My problem is i'm using boilerplate to most of my plugins. When i tried to include the plugin ...
  • Write a Plugin for WordPress Multi-Site (44)
    • An Quach
      - I always use single site because it's easy for me to managed. When I need another worpdress on subdomain or subfolder, I ...

Copyright © 2019 · Genesis Skins by ShibaShake · Terms of Service · Privacy Policy ·