How To Configure W3 Total Cache Settings Tutorial
Contents
- What is W3 Total Cache?
- How W3 Total Cache Works?
- Install W3 Total Cache
- W3 Total Cache on Nginx
- Configuring W3 Total Cache Settings
- Conclusion
What is W3 Total Cache?
W3 Total Cache is a free WordPress plugin designed to improve the speed of WordPress and reduce the resources consumed by your website from your hosting plan.
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
The first step is to install the W3 Total Cache plugin if you haven’t already. See my guide on how to install WordPress plugins if you’ve never installed a plugin before.
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.
Not including this config file for a Nginx server will cause some 404 errors for the included minified CSS and JavaScript files.
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:
/home/main/webfiles/antreno.com/public_html/nginx.conf
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.
A. Dashboard
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.
General

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.
Page Cache

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
- Memcached
- Redis
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.”
Minify

A very useful feature of the W3 Total Cache plugin is the ability to minify the CSS files, JavaScript and the HTML code of the page.
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.
Enabling the minify feature of W3 Total Cache can reduce the size of the CSS, JavaScript and HTML files delivered to your site’s visitors by up to 80% of their original size.
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.
Opcode Cache

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.
Database Cache

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.
Object Cache

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.
Browser Cache

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

“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.
A CDN will speed up your site by delivering your images, CSS, JavaScript, local font files, HTML files and caches files from the server with the fastest response time.
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.
Miscellaneous
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.
General
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.
Cache Preload

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.
Advanced
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.

D. Minify
The minify submenu contains all the options related to the file compression feature of W3 Total Cache. I find this feature to be very handy to reduce the size of my site’s CSS and JavaScript files.
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.
General

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.
Also, check the “Inline CSS minification,” “Inline JS minification,” and “Line break removal” options for the compression to be applied also to the inline CSS and JavaScript and to have the HTML comments removed from the source code of your site’s pages.
Leave the defaults for the “Ignored comment stems” option. The HTML comments that contain these values will be left untouched.
JS
The settings from this section allow you to choose what JavaScript files to minify, change the minification type, and choose the embed type.

First, enable the JS minify.
Leave the embed type “Before head” to “Default (Blocking).”
Leave the embed type “After body” to “Default (Blocking).”
Even though I would prefer a “Non-blocking” solution, I’ve tested all the other options, and only this configuration did not create JavaScript errors for my site after the file compression.
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.
CSS
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.
General

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
General
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.
J. CDN
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.
General
Once you have configured your CDN account, go to this section and tick all the options.

Configuration
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.
Advanced
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.
L. Monitoring
Nothing to edit for this page.
M. Extension
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.
Conclusion
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.
Hi,Marius
Nice article! Thanks for sharing.Meanwhile, I already did the W3TC settings and saved,but have no idea how to include nginx.conf file to server nginx.conf.
Now I use vultr vps,i found server nginx config file is at /www/server/nginx/conf/nginx.conf,W3TC file is at /www/wwwroot/mydomain/nginx.conf,I try to include W3TC file in it before the last },but failed, where is the problem?
I wonder if I need to pause nginx service firstly,then include,then restart it.Please kindly advise! By the way,is there any conflicts between autoptimize and W3TC plugin?
Thanks!
Hi Frederick,
Do you get any errors or your Nginx server doesn’t restart after you include the W3 Total Cache config file?
To make this work for my server, just before the closing “}”, I’ve added the following line (of course, you should use your path to the W3 config file):
Make sure you also add “include” and a space before the path of the config file.
Then, I had to go to the settings of W3 Total Cache plugin and cleared the caches and restarted my Nginx server.
If you disable the CSS/JavaScript minify options of W3 Total Cache and let Autoptimize handle these aspects, there should be no problems. I use Autoptimize + W3 Total Cache for one of my sites and everything works great.
Thanks Marius,
I tried again but failed,error shows:”nginx: [emerg] “location” directive is not allowed here in /www/wwwroot/mydomain.com/nginx.conf:2
nginx: configuration file /www/server/nginx/conf/nginx.conf test failed”.
I’m a VPS newbie and non-techie for centos,and manage my websites with a GUI control panel installed on centos/LEMP.If this problem remains,shall I install Apache to fully enable the W3TC function? LEMP+Apache means LEMP+LAMP combo or make a mess,thanks!
Hi Frederick,
I want to mention that I’m also not an expert in web servers.
Besides the line that should include the config file of W3 Total Cache, did you make any other changes to Nginx’s config?
Also, is everything wrapped in a server{} block?
If that error only occurs when you place the include line to the config, that’s most likely caused by the position where you insert it.
Someone on StackOverflow had a similar issue and that was the problem.
On my server (CentOS 7 + Nginx + VestaCP), the information of every domain name hosted on the VPS in the Nginx.conf file is enclosed in a server block.
I include the configuration file of W3 Total Cache just before the server block ending curly bracket ( } ).
It looks something like:
I’ve never used LEMP. I prefer VestaCP because it’s free and it already includes all the apps to run a website (Nginx or Apache, PHP, MySQL, mail server, FTP, etc.). Besides that, it also has a clean and simple interface for managing everything (something like a lightweight version of cPanel).
If you use Autoptimize plugin for the CSS and JavaScript code minification, I don’t even think you need to include the W3 Total Cache Nginx config file. I think those were the only functions that were not working properly before including the W3 config file.
I don’t think the solution is to install Apache. Even though for a beginner Nginx might be a bit of a pain when it comes to URL rewriting and things that require editing the config file, it’s still faster than Apache and needs fewer server resources.
From what I know, LAMP includes Apache, while LEMP includes Nginx server. So it’s one or another, not both.
Hi,Marius
Thanks so much and I really appreciate! You expound this issue very clearly,it’s very helpful.
You’re welcome, Frederick. Hope you found a solution to your problem.