- 1. Beginners Guide to Understanding WordPress Internal Functions
- 2. What is WordPress Caching and Why is it Important?
- 3. How does WordPress Caching Work?
- 4. How to Install & Setup WordPress Caching with WP Super Cache
- 5. Currently Reading: How to Setup WordPress Caching with W3 Total Cache (W3TC)
- 6. MaxCDN Review: The Best CDN for WordPress?
The world’s two most popular WordPress caching plugins are WP Super Cache and W3 Total Cache (W3TC). Developed by Mashable’s CTO, W3 Total Cache is by far the most versatile WordPress caching plugin available, used in high traffic sites like Smashing Magazine, Mashable, MakeUseOf and Yoast. This tutorial is a beginner’s guide to configuring W3 Total Cache. Word of advice: W3TC has a plethora of advanced settings some of which I have a hard time comprehending. If you’re unfamiliar with a setting it’s best not to mess with it. Let’s begin!
Install W3 Total Cache
To install the W3 Total Cache plugin, open your WordPress dashboard, followed by Plugins > Add New. Search for “w3 total cache” and install the first result. You can also manually download the plugin and upload it to the wp_content/plugins folder via FTP. If you have previously installed another caching plugin like WP Super Cache, you should disable it before activating W3 Total Cache. This would prevent the two plugins from conflicting. As a rule of thumb, don’t keep more than one WordPress caching plugin activated at any given time.
Configuring W3 Total Cache – General Settings
W3 Total Cache creates a new menu entry called Performance in WordPress dashboard. The options that we’re looking for are under Performance > General. You’ll notice that this page has an overwhelming number of settings for a caching plugin (and a whole lot more if you’re into advanced stuff). Each setting is placed inside a box – called modules. I’ve discussed each of these modules with relevant screenshots. If you get stuck or are uncertain about a particular setting, simply follow the screenshots.
The first module you’ll find is General. I’d recommend not to enable the all the caching options using the toggle checkbox. You might turn on settings that aren’t required (or even supported by) your host – which would inadvertently slow down your website. However, if you want to quickly disable all the modules, this toggle checkbox comes in handy! Before we proceed further, if you’re unfamiliar with the terms ‘page cache’ or ‘database cache’, I would recommend reading How WordPress Caching Works.
Page Cache Module
The second module we’re going to configure is Page Cache. The Page cache method depends on your hosting environment. If you’re using a shared host, Disk: Enhanced is the best option. However, if you’re using a dedicated or virtual server and you have APC (or any other form of Opcode caching installed), you should select the respective option.
Other Caching Modules
The next two modules are Database Cache and Object Cache. Enable each of them and change their caching method to the one best fit to your hosting environment – just like you did under Page Cache and Minify.
The last module that we want to enable is Browser Cache. Once you’ve enabled them, click on Save all Settings. That should do it! W3 Total Cache is now enabled in your server. We will now take an in-depth look into two specific modules – Page Cache and Browser Cache. The rest of the modules’ default values are just fine.
Page Cache Settings
The Page Cache settings can be found under Performance > Page Cache. The settings here are fairly self explanatory. I’ve enabled a couple of them – specially Don’t cache pages for the following user roles. This ensures that when an author is editing a post, he/she will able to view the latest version and not the one from the cache.
Preloading the Cache
By default, W3 Total Cache caches a page when it is first requested. You also have the option to pre-generate copies of all the posts/pages. This way, regardless of when a visitor requests a page, the cache is ready and the page is served in the lowest possible time.
You should configure the cache preload settings based on your hosting environment and the amount of traffic your website receives.
- The cache Update interval directly affects server resources – lower the time interval (i.e. higher the frequency), greater the server resource consumed. People on shared hosting servers should be very careful with this setting. Set a high enough frequency and you might just get your account suspended for abuse of server resources. A safe cache preload interval is one hour – i.e. 3600 seconds.
- If you’re unfamiliar with the Sitemap URL, install Google XML Sitemaps. It’s super easy to use and is in fact, a must-have plugin.
- Finally, you want to enable the last option which will trigger a cache preload operation when a post/page is published.
Browser Cache Settings
How do you know that W3 Total Cache is actually working? Well, the plugin page says so. You can also view the source code of your site find something like this:
W3 Total Cache Performance Benchmark
I waited around 1 hour after I enabled caching and benchmarked the website’s performance using GTmetrix. This is without any caching plugin:
This is one hour after W3 Total Cache was configured:
Notice the difference? A 3% and 5% increase in Page Speed and YSlow Grade. Neat, right? Now imagine a thousand people visiting your site daily – imagine the amount of CPU cycles (fancy term for resource usage) you’ll save. Caching not only reduces you page size, but it also improves the overall site’s performance which paves the way to a great user experience.
Troubleshooting W3 Total Cache
You might notice that your site’s load time has increased after installing W3 Total Cache. Is that even possible? Of course it is! In fact, this is a very common beginner’s mistake. There can be a lot of reasons behind this:
- The most probable reason is that you’ve conducted the website benchmark while preloading the cache. Building the cache consumes considerable server resources. Imagine your request on top of that – of course your site would become slow! Solution: wait for an hour and try again – this time it should be different.
- Another common reason is selecting the wrong caching methods. Let me tell you that anything other than Disk caching involves certain amount of A/B testing. You need to play with some of these settings in order to squeeze the best possible result.
- Sometimes on a shared server you might find APC or some other Opcode caching option available – and it’s likely that you’ve selected it. Don’t! Revert to ‘Disk’ or ’Disk Enhanced’. The reason being that those settings have been fine-tuned for the overall performance of the shared server – remember you’re not the only person using it. These settings might not work with W3 Total Cache.
If you’re still facing problems and you’ve tried the default/recommended values, I recommend switching to WP Super Cache.
.htaccess File Permission Error
Depending on your hosting environment, you might see an error message stating that your .htaccess file isn’t writable. This means that the webserver and/or PHP handler does not have the permission required to modify the .htaccess file. There are two solutions:
- You change the permission of the .htaccess file to 775 via FTP or cPanel, etc.
- You manually add the data to the .htaccess file
I must point out that the second method is safer and is considered a good security practice.
Conclusion – Which Plugin Should I Use?
You might be wondering which WordPress caching plugin to use. After all, I did write two separate tutorials to achieve the same goal. Should you go for WP Super Cache or W3 Total Cache? Well, to make a long story short – if you’re on a shared server and don’t want the hassle of A/B testing and/or troubleshooting, WP Super Cache is much easier to implement. However, if you’re using a virtual or dedicated server with Opcode caching (like APC or XCache) installed – and wouldn’t mind some extra work, then W3 Total Cache is for you. When configured properly with advanced methods, W3TC’s results are far superior.
This concludes setting up our caching plugins. I’ll also discuss how to setup a CDN with each of these plugins. In the meantime, you could check out some of the best free CDNs for WordPress and stay tuned.
Parting question: What’s your favourite caching plugin? How much difference did it make in your site’s performance? We’d love to hear from you!