- 1 What is W3 Total Cache?
- 2 How W3 Total Cache Works?
- 3 Install W3 Total Cache
- 4 W3 Total Cache on Nginx
- 5 Configuring W3 Total Cache Settings
- 5.1 A. Dashboard
- 5.2 B. General Settings
- 5.3 C. Page Cache
- 5.4 D. Minify
- 5.5 E. Database Cache
- 5.6 F. Object Cache
- 5.7 G. Browser Cache
- 5.8 H. User Agent Groups
- 5.9 I. Referrer Groups
- 5.10 J. CDN
- 5.11 K. Fragment Cache
- 5.12 L. Monitoring
- 5.13 M. Extension
- 6 Conclusion
What is W3 Total Cache?
The W3 Total Cache is one of the most popular WordPress caching plugins, and according to the stats displayed on its presentation page in the official WordPress plugins directory, it currently has over one million of installations.
I use this plugin for almost all my sites powered by WordPress (see here what other plugins I usually use), and even though there are many similar plugins and I’ve tested a part of them, I think W3 Total Cache is the most powerful.
The good part is that you can use this plugin for absolutely no cost.
The bad part is that it’s not a plugin which is easy to configure for a beginner and some of the settings of W3 Total Cache plugin will have to be set based on the configuration of your web hosting server, installed caching modules, and so on.
Without a proper knowledge regarding how a website works and a basic understanding of the technical terms, the multitude of settings of the W3 Total cache plugin might be overwhelming.
In this post, I will try to explain which is the best configuration of W3 Total Cache and how to set these options in the best way possible for obtaining the best performance for your site.
How W3 Total Cache Works?
WordPress saves all its data in a database. This data can include post content, pages, tags, categories, settings, image URLs, theme and plugin options, and any other data that is not directly loaded from the WordPress files.
When a dynamic page is loaded, WordPress will run a few processes to get this data out from the database and display it on that page. These processes are called in technical terms “database queries”.
Each database query will add extra time to the page execution time, and the more database queries are performed when a page is loaded, the slower that page will be.
Some database queries will only add milliseconds to the page loading time, but other can add seconds.
A typical WordPress dynamic page executes about 50 database queries every time it loads. This number can increase if your site has many active plugins, widgets, multiple menus, related posts, etc.
Now, if a page executes 50 database queries every time a page is loaded, think about how many queries are executed per second when 100 users are simultaneously online on your site and view your content.
Your server needs to process a lot of queries per second if your site is popular and these database queries will consume bandwidth and CPU from your web server.
Besides that, a slow site will not only lose traffic and conversion, but the site speed has also become a lightweight SEO ranking factor.
Now, here comes the critical role of using a caching plugin.
A caching plugin will save this data in caches and reuse this information the next time the page is loaded. Instead of executing hundreds of database queries every time the page is loaded, now WordPress will serve the page content from the cached data.
The cached data is just temporary site data stored in the form of static files. When a page is stored in caches, the content of that page is served from these static files instead of the database, until the caches expire, are cleared or regenerated.
Your site will become faster, will consume fewer resources from your web hosting plan, and it also helps you get rid of most of the warnings from Google’s PageSpeed Insights.
Install W3 Total Cache
After W3 Total Cache is installed and active, you need to configure its settings so that the plugin function correctly and give your site the best performance.
You can find all the W3 Total Cache setting under the “Performance” menu.
W3 Total Cache on Nginx
Two of the most common HTTP servers are Apache and Nginx.
Most of the shared hosting plans will use Apache, but if you have your website hosted on a VSP or Dedicated server and you use Nginx, then you’ll also have to include a config file autogenerated by the plugin to the root of your site’s directory.
If you don’t know what your hosting uses, then just ignore this step.
You can see the full path to the config file under the “Performance –> Install” menu, “Rewrite rules” section.
It will look something like:
I won’t get into details about this since the majority of the shared web hosting plans use Apache, and there’s no need to perform this step in that case.
If you have problems concerning this step, leave me your questions in the comments area.
The install page also includes a list of recommended settings and software.
Configuring W3 Total Cache Settings
The settings of the W3 Total Cache plugin are grouped into multiple submenus to enable you to find the desired options easily.
Further, I’m going to take you through all of these submenus and tell you what settings you need to change in order for your site to achieve the best performance.
The dashboard submenu doesn’t have any settings. This is the area where you can perform a compatibility check or clear the various cache types.
The compatibility check button will display a popup with various technical information about your site.
B. General Settings
This page allows you to enable or disable the various caching types, enable debugging, configure a few general options, and import/export the W3 Total Cache settings.
From this section, you can enable or disable all caching types at once.
I do not recommend using this option since you might not need all the options activated. Instead, just go through the settings and configure each option based on this guide.
The Preview mode is useful when you first install W3 Total Cache on a production site. Enabling this mode allows you to see if everything works correctly before applying the configuration to your live website.
I usually just ignore this section.
Enable the “Page Cache” option.
The page cache allows W3 Total Cache to save the content of your pages in caches and deliver these static pages to your visitors instead of pulling page content from the database every time the page loads.
“Page Cache Method” allows you to select where you want the page caches to be stored.
The available options are dependent on the configuration of your web server and the installed modules.
- Disk: Basic
- Disk: Enhanced
- Opcode: Alternative PHP Cache (APC / APCu)
- Opcode: eAccelerator
- Opcode: XCache
- Opcode: WinCache
Setting the value of this option to “Disk: Enhanced” should work for most configurations. If you notice any issues when you set this option, then just switch to “Disk: Basic.”
A minified script has all the comments and whitespaces removed. The comments and whitespaces are only useful for developers and removing these will reduce the file size and will speed up the script execution time.
Since the files will have a lower size, your site will consume less bandwidth from your hosting plan.
Therefore, enable the “Minify” option.
Set the “Minify mode” to “Auto” so the plugin choose the files to be minified automatically.
The recommended value for the “Minify Cache Method” is “Disk,” because this option is available for all the web servers and shouldn’t create any issues.
When it’s available, I usually set this to “Opcode: Alternative PHP Cache (APC / APCu).” If this option is not available for you, just choose “Disk.”
Leave “HTML minifier” to the default value, which is “Minify (default).”
Leave “JS minifier” to the default value, which is “JSMin (default).”
Leave “CSS minifier” to the default value, which is “Minify (default).”
If your server uses Nginx, you will have to include the config file autogenerated by the W3 Total Cache plugin in the root directory of your site to your server’s nginx.conf file (see the W3 Total Cache on Nginx section above). Otherwise, you will receive 404 errors for the URLs of the minified files.
Even though “Opcode cache” seems to be installed on my server according to the compatibility check, this option is not available for me. Maybe this setting requires something else installed, another Opcode cache version, or depends on another option.
You should probably see the same “Not Available” message.
So, I’ll just skip this section.
WordPress is a script which relies heavily on working with a database. The database cache feature of this plugin, caches the most commonly used database queries to speed up this process.
According to the instructions offered by the W3 Total Cache plugin under the “Install” submenu, enabling this option for some shared web hosting plans might slow down your site if the “Disk” option is selected and the disk is not fast enough.
The recommended option is to select an in-memory solution like “Opcode: Alternative PHP Cache (APC / APCu)” or “Memcached” if available.
If only the disk option is available, select that and see if your site loads faster or slower with this option enabled. If you notice speed drops, just disable this option.
I use “Opcode: Alternative PHP Cache (APC / APCu)” as the database cache method for my site.
WordPress often stores the data pulled from the database as objects. If you enable this option, these objects will be temporarily saved in caches to reduce the number of database queries.
Just as for the database cache, W3 Total Cache plugin creators warn us that this option might slow down your site on shared hosting plans when the “Disk” option is selected as the object cache method.
Again, “Opcode: Alternative PHP Cache (APC / APCu)” or “Memcached” are recommended.
This feature allows your site to use the caches available in visitor’s web browser. This will reduce the load on your web server and its response time.
Enabling this option should also help you get rid of the “Leverage browser caching” warning from Google PageSpeed Insights.
I recommend you to enable this option.
“CDN” stands for “Content Delivery Network” or “Content Distribution Network” and is a system of web servers across the world intended to deliver your site’s static files from the web closest server from visitor’s location.
Besides that, a CDN will reduce your site’s bandwidth consumption and adds a few security features.
If you want to know more about a content delivery network, read my post about how to set up a CDN for your WordPress site.
I use KeyCDN for my blog, because it’s cheap and has many benefits (read the guide mentioned above for a complete guide for setting up KeyCDN with WordPress and W3 Total Cache). Register your account with KeyCDN today and receive $10 (250GB) in traffic credits.
I truly recommend you to use a CDN service for your site, especially if you write posts with a lot of images like me. Your images will load almost instantly and way faster than when your images are delivered from your disk.
Enable this option after you have decided to use a CDN.
I jumped a few sections since you don’t have to change anything there.
Here’s how my settings in the “Miscellaneous” section look like.
There’s no need to edit any other settings on this page.
The next submenus under “Performance” allow us to edit the settings of the features enabled under “General Settings.”
C. Page Cache
Since we have activated the page caches, we can now modify the settings of this feature from this page.
Below are the settings I use for the General section.
Cache posts page – in WordPress, this is the page where you see the post content (the exact page you see right now). Enable this option to allow W3 Total Cache to save this page in cache.
Don’t cache front page – if you enable this setting, the front page of your site won’t be cached (https://antreno.com is my site’s front page). Since I don’t see any reasons for preventing this page from being cached, I just leave this option disabled.
Cache feeds: site, categories, tags, comments – This option allows you to choose whether you want to permit the plugin to cache the categories, tags, and comments. I want these cached as well to optimize my blog as much as possible, so I just enable this option.
Cache SSL (https) requests – If your site has an SSL certificate installed and it’s accessible with https:// (like my site) in front of the domain name, I recommend you to enable this option.
Cache URIs with query string variables – This option is disabled and you can’t enable it (probably because no one would want the search results cached).
Cache 404 (not found) pages – There’s no need to cache the 404 error pages. Just leave this setting disabled.
Don’t cache pages for logged in users – Caching the pages for the logged in users might cause additional problems. Unless you have a community site with many users logged simultaneously on your website, enable this option. Also, since I usually disable the user registration in WordPress and I’m the only registered user, there’s no point in caching the pages only for me.
Don’t cache pages for following user roles – If you choose to activate page caching for the logged in users, you have the option to skip disable the caching for specific user roles. I have Administrator “Administrator,” “Editor,” and “Author” selected, but since I chose not to cache the pages for the logged in users, these don’t make any difference.
Check “Automatically prime the page cache.”
Leave the “Update interval” to the default value (900).
Leave the “Pages per interval” to the default value (10).
Check “Preload the post cache upon publish events.”
Enter the URL of your XML sitemap in the “Sitemap URL” field if you have one.
I use the Yoast SEO plugin to generate the XML sitemap for my site and the sitemap it’s accessible at https://antreno.com/sitemap_index.xml. Read my guide on WordPress SEO for a full tutorial on how to make your WordPress blog SEO friendly using the Yoast SEO plugin.
I leave all the other settings on this page to their default value. However, there’s a specific option that you might want to enable.
On the “Install” page of W3 Total Cache, there’s a recommandation to enable the “Compatibility mode” under the “Advanced” section.
The “Compatibility Mode” option found in the advanced section of the “Page Cache Settings” tab will enable functionality that optimizes the interoperability of caching with WordPress, is disabled by default, but highly recommended. Years of testing in hundreds of thousands of installations have helped us learn how to make caching behave well with WordPress. The tradeoff is that disk enhanced page cache performance under load tests will be decreased by ~20% at scale.
The downside of enabling this mode is that the disk enhanced cache speed will decrease by 20%.
I haven’t activated this option and everything works OK on my site, but I think this might depend from one web host to another. Therefore, if you want to reduce the chance of having compatibility issues, you should enable this option. The plugin probably recommends you to enable this for a good reason.
I also enable the HTML code minification to reduce the size of my pages as much as possible. The web browsers and crawlers don’t need the line breaks or the HTML comments.
Rewrite URL structure – This option is enabled by default and you should leave it like that in most of the cases.
Disable minify for logged in users – I have the user registration disabled and I am the only person who can log in to my site, so I just typically keep this option unchecked.
Minify error notification – If the W3 Total Cache encounters problems compressing the files, you can get notified by email, in the WordPress dashboard, or both. Just set this option to your favorite way of receiving notifications.
HTML & XML
The W3 Total Cache plugin enables you to also compress your pages HTML code and XML.
Enable the “HTML minify settings” option to activate this feature.
Leave the defaults for the “Ignored comment stems” option. The HTML comments that contain these values will be left untouched.
First, enable the JS minify.
Leave the embed type “Before head” to “Default (Blocking).”
Leave the embed type “After body” to “Default (Blocking).”
Select “Minify” as the compression type.
Check “Preserved comment removal” and leave unchecked the “Line break removal” option since the plugin marks this option as unsafe.
Leave the “HTTP/2 push” option unchecked if you’ve selected “Disk: Enhanced” as the page cache method under the “General Settings” submenu as recommended in this tutorial. Otherwise, enable this option.
This section contains a few options concerning CSS files compression.
If the option is not already enabled, check the “Enable” option.
Leave “Combine only” unchecked.
Check the “Preserved comment removal” option.
Check the “Line break removal” option.
The option for eliminating the render-blocking CSS by moving it to HTTP body is only available for the premium users, so unless you have a premium license, you can only leave this option disabled.
Leave the “@import handling” to “None.”
Leave the “HTTP/2 push” option unticked if you have selected “Disk: Enhanced” as the page cache method under the “General Settings” submenu as recommended in this guide. Otherwise, enable this option.
No need to modify anything else on this page.
E. Database Cache
You only have to check one thing here.
Just make sure the “Don’t cache queries for logged in users” option is ticked.
F. Object Cache
Only make sure the following options are unticked.
You don’t want the requests for the WordPress admin area to be cached, so uncheck “Enable caching for wp-admin requests” option.
I also don’t like to store the transients in the database since that will increase the size of the database. Therefore, I just leave the “Store transients in database ” option unchecked.
G. Browser Cache
Heres are my settings for this section.
CSS & JS
Below is a screenshot of the CSS & Js section.
HTML & XML
Media & Other Files
H. User Agent Groups
There’s no need to modify anything here.
I. Referrer Groups
There’s no need to modify anything here.
You only have to change a few settings here if you want to speed up your site even more by integrating a content delivery network.
See my step-by-step guide on how to integrate a CDN with WordPress and W3 Total Cache.
Register an account with KeyCDN using my special link and receive $10 in traffic credit for free.
Once you have configured your CDN account, go to this section and tick all the options.
Based on what content delivery network you choose and the option set for the “CDN Type” option under “General Settings,” a few different option fields will become available.
If you use KeyCDN (as I use), you will only see two configurable settings under this section and a button for testing the connection with the CDN.
If your CDN has an SSL certificate and your files include the https:// protocol at the beginning of the files, set the “SSL support” option to “Enabled (always use SSL).”
Set the URL of your CDN in the “Replace site’s hostname with” field.
Only activate the “Set cookie domain to yourdomain.com” option and leave all the other options to their defaults.
K. Fragment Cache
The fragment cache is a feature only available for the premium version of W3 Total Cache. Since I use the free version, I just don’t have to modify any settings here.
If you disable the “Fragment Cache” extension from the “Extensions” submenu, then this page will disappear.
Nothing to edit for this page.
The W3 Total Cache plugin has a few extensions that you can activate from this page if you use specific services or WordPress plugins.
A few extensions are enabled by default, but I usually only keep the “Yoast SEO” extension active because I use the Yoast SEO plugin. If you also use this plugin, keep this extension active to configure the W3 Total Cache plugin to comply with Yoast SEO automatically.
Even though W3 Total Cache is not the easiest plugin to configure and its settings cannot be set in a general way that suits all the web servers, it’s one of the essential plugins I use for every WordPress site.
W3 Total Cache not only makes my website faster but also helps me save money on web hosting.
Besides that, a fast website also has a small advantage when it comes to SEO, has a lower visitor abandonment rate, a higher conversion rate, and more happy visitors.
The website speed is critical nowadays in a world where everybody is in a hurry. An additional second added to the page loading time can make a huge difference in gaining a customer and missing a customer.
I hope that this guide on how to configure W3 Total Cache settings is going to help you to achieve the best performance for your WordPress site.