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

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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Recent Posts

  • Screenshot of an example article in code view of a modified Gutenberg editor.How to Harness the Power of WordPress Gutenberg Blocks and Combine It with Legacy Free-Form Text
  • Screenshot of the Success, WordPress has been installed page.Migrating Your WordPress Website to Amazon EC2 (AWS)
  • Screenshot of WinSCP for creating a SFTP configuration.How to Set-Up SFTP on Amazon EC2 (AWS)
  • WordPress Gutenberg code view screenshot of this article.How to Prevent Gutenberg Autop from Messing Up Your Code, Shortcodes, and Scripts
  • Screenshot of the Success, WordPress has been installed page.How to Create a WordPress Website on Amazon EC2 (AWS)

Recent Comments

  • Create Pop-up Windows in Your WordPress Blog with Thickbox (57)
    • Jim Camomile
      - I have used this tutorial several times and it is one of the few simple and effective ways to add popups with dynamic content, ...
  • How to Add Admin Columns in WordPress (7)
    • Andy Globe
      - Hi Friends, I am facing two problem in WordPress admin1. Load custom CSS for wp-admin on user-role base (editor) 2. ...
  • Example blog front-page using excerpts and the Shiba Theme.Optimize Your WordPress Plugins with Tags (5)
    • DF
      - thanks, i went the other way and added a filter if pages I wanted.
  • WordPress Search Widget – How to Style It (57)
    • Nelson
      - Tanks master - Fine
  • Update custom inputs with the proper data using Javascript.Expand the WordPress Quick Edit Menu (59)
    • Mike G
      - This is exactly what is happening to me. It is updating the value in the database and in the column, but I have to refresh ...

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