{"id":8248,"date":"2010-12-08T10:36:54","date_gmt":"2010-12-08T18:36:54","guid":{"rendered":"http:\/\/shibashake.com\/wordpress-theme\/?p=8248"},"modified":"2012-10-14T12:51:16","modified_gmt":"2012-10-14T19:51:16","slug":"w3-total-cache-cookie-is-rejected","status":"publish","type":"post","link":"https:\/\/shibashake.com\/wp\/w3-total-cache-cookie-is-rejected","title":{"rendered":"W3 Total Cache &#8211; Cookie Is Rejected"},"content":{"rendered":"<p>Recently, I switched over to <a href=\"http:\/\/wordpress.org\/extend\/plugins\/w3-total-cache\/\">W3 Total Cache<\/a>. Reasons for the switch &#8211;<\/p>\n<ul>\n<li>There have been a lot of great reviews and raves about W3 Total Cache.<\/li>\n<li>W3 Total Cache offers a very comprehensive caching solution.<\/li>\n<li>I was having caching issues on my multi-site setup.<\/li>\n<\/ul>\n<p>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 <a href=\"http:\/\/www.w3-edge.com\/\">Frederick Townes<\/a> for creating such an awesome plugin.<\/p>\n<p>This article describes some common W3 Total Cache issues and how to fix them.<\/p>\n<div class=\"alignspace\"><\/div>\n<h2>1. W3 Total Cache &#8211; Cookie Is Rejected<\/h2>\n<p>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. <\/p>\n<p>Here is an <a href=\"http:\/\/wordpress.org\/support\/topic\/plugin-w3-total-cache-cookie-is-rejected-with-firefox\">explanation by Frederick Townes<\/a>.<\/p>\n<p>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. <\/p>\n<p>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.<\/p>\n<p>A simple way to fix this is to use the <em>comment_cookie_lifetime<\/em> filter which will only get applied for non-logged in users. <\/p>\n<p><pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ Add filter to the init function of your theme functions.php file\r\nadd_filter('comment_cookie_lifetime', 'my_comment_cookie_lifetime');\t\r\n\t\r\nfunction my_comment_cookie_lifetime($lifetime) {\r\n\treturn 10;\r\n}\r\n<\/pre>\n<\/p>\n<p>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.<\/p>\n<p>You can test this by turning on Page Cache debugging in the main <strong>Performance >> General Settings<\/strong> screen.<br \/>\n<div id='&#8221;8255&#8243;' class='wp-caption frame6 &#8221;aligncenter&#8221;' style='width:auto' ><div class='shiba-outer shiba-gallery' ><div class='shiba-stage' style='width:auto'><img loading=\"lazy\" src=\"https:\/\/shibashake.com\/wordpress-theme\/wp-content\/uploads\/2010\/12\/w3-total-cache5-520x196.jpg\" alt=\"Turn on Page Cache debugging in Performance &gt;&gt; General Settings.\" title=\"w3-total-cache5\" width=\"520\" height=\"196\" class=\"size-large wp-image-8255\" srcset=\"https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache5-520x196.jpg 520w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache5-300x113.jpg 300w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache5-460x173.jpg 460w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache5-220x82.jpg 220w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache5.jpg 782w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><div class='wp-caption-text shiba-caption'>&#8221;Turn<\/div><\/div> <!-- End shiba-stage --><\/div><\/div><\/p>\n<div class=\"alignspace\"><\/div>\n<h2>2. W3 Total Cache &#8211; URL Redirect Issues<\/h2>\n<p>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 <strong>before<\/strong> the W3 Total Cache rules.<\/p>\n<p>For example &#8211;<\/p>\n<pre class=\"brush: xml; gutter: false; title: ; notranslate\" title=\"\">\r\nRewriteEngine On\r\nRewriteBase \/\r\nRewriteCond %{HTTP_HOST} ^www.site.com$ [NC]\r\nRewriteRule ^(.*)$ http:\/\/site.com\/$1 [R=301,L]\r\n\r\n# BEGIN W3TC Page Cache\r\n&lt;IfModule mod_rewrite.c&gt;\r\n...\r\n<\/pre>\n<\/p>\n<p>Here is a <a href=\"http:\/\/wordpress.org\/support\/topic\/after-w3-total-cache-redirect-domainde-to-wwwdomainde-does-not-work\">discussion of the redirect issue and the fix<\/a>.<\/p>\n<div class=\"alignspace\"><\/div>\n<h2>3. W3 Total Cache &#8211; Duration of Page Cache Files<\/h2>\n<p>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.<\/p>\n<div id='8249' class='wp-caption frame6 aligncenter' style='width:546px' ><div class='shiba-outer shiba-gallery' ><div class='shiba-stage' style='width:520px'><img loading=\"lazy\" src=\"https:\/\/shibashake.com\/wordpress-theme\/wp-content\/uploads\/2010\/12\/w3-total-cache2-520x369.jpg\" alt=\"W3 Total Cache - Changing the file expiration time of the files in your Page Cache.\" title=\"w3-total-cache2\" width=\"520\" height=\"369\" class=\"size-large wp-image-8249\" srcset=\"https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache2-520x369.jpg 520w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache2-300x213.jpg 300w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache2-460x327.jpg 460w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache2-220x156.jpg 220w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache2.jpg 967w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><div class='wp-caption-text shiba-caption'>W3 Total Cache - Changing the file expiration time of the files in your Page Cache.<\/div><\/div> <!-- End shiba-stage --><\/div><\/div>\n<p>As stated in the notes section at the bottom of the Page Cache screen &#8211;<\/p>\n<blockquote>\n<p>The TTL of page cache files is set via the &#8220;Expires header lifetime&#8221; field in the &#8220;HTML&#8221; section on Browser Cache Settings tab.<\/p>\n<p>TTL = time to live.\n<\/p>\n<\/blockquote>\n<div id='8250' class='wp-caption frame6 aligncenter' style='width:546px' ><div class='shiba-outer shiba-gallery' ><div class='shiba-stage' style='width:520px'><img loading=\"lazy\" src=\"https:\/\/shibashake.com\/wordpress-theme\/wp-content\/uploads\/2010\/12\/w3-total-cache3-520x337.jpg\" alt=\"Changing your Page Cache duration also requires a change in the Browser Cache screen.\" title=\"w3-total-cache3\" width=\"520\" height=\"337\" class=\"size-large wp-image-8250\" srcset=\"https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache3-520x337.jpg 520w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache3-300x194.jpg 300w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache3-460x298.jpg 460w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache3-220x142.jpg 220w, https:\/\/www.shibashake.com\/wp\/wp-content\/uploads\/2010\/12\/w3-total-cache3.jpg 808w\" sizes=\"(max-width: 520px) 100vw, 520px\" \/><div class='wp-caption-text shiba-caption'>Changing your Page Cache duration also requires a change in the Browser Cache screen.<\/div><\/div> <!-- End shiba-stage --><\/div><\/div>\n<div class=\"alignspace\"><\/div>\n<h2>4. W3 Total Cache &#8211; WordPress Multi-Site Settings<\/h2>\n<p>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. <\/p>\n<p>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.<\/p>\n<p>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.<\/p>\n<p>Here is a <a href=\"http:\/\/wordpress.org\/support\/topic\/plugin-w3-total-cache-w3tc-htaccess-doesnt-seem-to-work-with-a-multi-site-setup\">thread discussing this issue in detail<\/a>.<\/p>\n<p><strong>Note &#8211; 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. <\/strong><\/p>\n<div class=\"alignspace\"><\/div>\n<h2>W3 Total Cache Is Awesome!<\/h2>\n<p>The purpose of this article is to summarize some of the things I learned while setting up W3 Total Cache. <\/p>\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I switched over to W3 Total Cache. Reasons for the switch &#8211; 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8249,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":""},"categories":[295],"tags":[903,901,902,907,908,910,909,906,900,899,905,904,573],"_links":{"self":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts\/8248"}],"collection":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/comments?post=8248"}],"version-history":[{"count":15,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts\/8248\/revisions"}],"predecessor-version":[{"id":10691,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/posts\/8248\/revisions\/10691"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/media\/8249"}],"wp:attachment":[{"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/media?parent=8248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/categories?post=8248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shibashake.com\/wp\/wp-json\/wp\/v2\/tags?post=8248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}