W3 total cache is by far the best plugin for caching and optimizing the front end of WordPress. I say front end because there is a lot more that can be done on the back end. If you would like to know more about that you can send me an email via the contact page. Back end optimization is for VPS and Dedicated servers as shared hosting is very limited to what can be done.
You might be thinking why I decided to write this guide, the simple answer is even though there are other great guides out there the simple fact is not enough people configure this plugin correctly and so they have it installed but it’s not doing anything other than using resources. So I am going to go through all the configuration you need to get this plugin working to it’s maximum potential for your site.
Ok let’s do this.
No point reading any further if you don’t have the plugin installed.
- Head over to plugins in your wordpress admin panel.
- Select add new
- Type W3 total cache
- Select install now
Some issues you may face:
You may encounter an error or warning about permissions for wp-content needing to be 777 or 755, to change permissions head to your cpanel or whatever interface your using for your server and open the file manager.
Right click on wp-content and select change file permissions and change accordingly.
If you are required to change to 777, change it back to 755 after install.
Now you have the plugin installed and activated you can move on to configuring the plugin.
Look to the right of your admin panel, you should see a menu called Performance.
Select this and you will be take to a screen just like this.
Click to view a larger images
First thing you need to do is select disable where is says Preview mode is active:
You won’t believe how many times I have seen this enabled, so even if you configure the plugin it will still do nothing while in preview mode so disable it.
Next while still in general settings ensure that the following boxes are checked.
- Page Cache (Note this is not necessary for all)
- Browser Cache
We will look at Minify and CDN further down.
So once the general settings are configure head over to page cache by selecting the link either in the sidebar to the left or at the top of W3’s general settings page.
Inside page cache settings ensure the following options are enabled.
- Cache post page
- Don’t Cache front page ( use this if you have dynamic content on your home page – such as latest posts, sliders etc)
- Cache feeds: site, categories, tags, comments
- Cache requests only for sitename.com site address
- Don’t cache pages for logged in users
- Garbage collection interval:
This setting depends on how busy your site is. The default is 3600, but you could lower this if you have a busy site because it will use up disk space and if left unchecked you will soon run out, just like your browser if you don’t clear cache with tools such as C-cleaner you will find your hard drive filling up everyday. So the job of garbage cleaner is to remove old cache.
There are no more settings that need to be looked at in advanced.
Also known as priming is used to preload the most important pages on your site.
- Tick the box to enable it
- Update interval: 900
- pages per interval: 10
- Add you sitemap which should be sitename.com/sitemap.xml
There should be no need to change the default settings here.
Object & Database Caching
Both these settings are not required and in many cases can cause issues that outweigh any potential gains.
This is the one that most people forget to configure. In it’s default state it looks like this.
This is where the biggest gains for your site will occur and yet the default settings exclude these vital optimization techniques so you should enabled the following.
Set expires header
This option is there to encourage the browser to cache resources locally. I.e. on your computer. This helps to reduce the load to the server for returning visitors which is always a good thing, because we want maximum performance with the ability to serve as many people as possible without making the server unstable.
The Expires Header is enabled for all resource types and you can specify the timeout for each of the following:
- CCS & JS – Set the Expires header lifetime: (31536000) seconds, which is 1 year.
- HTML & XML – Set the Expires header lifetime: (3600) seconds, which is 1 hour.
- Media & Other files – Set the Expires header lifetime: (31536000) seconds, which is 1 year.
The options to specify are located further down the options page as you scroll down. For each you can specify the following options:
Set cache control header
Cache control Headers are basically the policy of your cache, the header information assigned to each file determines how long the file is considered fresh, to do that we need to apply a cache control header so the browser knows how long to store the representation of the file, before requesting an updated version.
Typically I would use:
cache with max-age ("max-age=EXPIRES_SECONDS, public, must-revalidate, proxy-revalidate")
To break this down a little, it is saying.
- Cache the file using max age – I.e. the time in seconds that you set in the Expires header.
- Public – This marks authenticated responses as cacheable.
- must-revalidate – this ensures that the cache will be updated when the Expires headers max age expires. HTTP cache allows browsers to cache stale representations, so here we are simply saying, obey the max-age.
- proxy-revalidate – similar to must-revalidate, except it only applies to proxy cache. A CDN that serves cache, would be an example of proxy cache, because it is not on your main server.
Set W3 cache header
As it says this is just assisting in identifying optimized files.
Enable HTTP (gzip) compression (this will only work if your server permits it)
Gzip compression can boast some of the largest gains in terms of performance, but it does require more power and resource ussage from the server.
It is for this reason, that most shared hosts do not allow it. Shared hosts are already at there limits, enabling gzip compression would most certainly crash a shared host. But if your on a VPS or Dedicated server you will see big gains from this.
Your completed configuration should be as follows:
Do not enable the following:
Set entity tag (eTag)
You should turn these off by adding the following to your .htaccess file found in the root folder of your site via the file manager. Remember to select show hidden files otherwise you won’t see it in cpanels file manager.
Header unset ETag FileETag None
Adding this to your .htaccess will also remove other server generated queries, some users may see something like ?132490 appended to all resources, that would be an E-tag, so if you still have lots of queries after configuring W3 then make sure you disable and unset all Etags or you may still see a query appended to static resources.
If you want to remove all other query strings that are not encoded directly to the resource then you can use this function found here.
Prevent caching of objects after settings change
Again do not enable this, it will turn your resources in to queries and this is bad for caching, bad for CDN’s and bad for performance.
Content Delivery Network
There are plenty of content delivery networks out there, but the ones that I have had the most experience with are amazons S3/Cloudfront and Max CDN which is what I use.
There are pros and cons to all CDN’s but what I like about Max CDN is the simplicity in setting it up as well as the pay as you go payment method.
I will be writing further posts about setting up both Amazon s3/Cloudfront and Max CDN.
This option should never be enabled as it can cause unexpected issues. A well developed site will have no need for minification if the smart use of resources are enacted.
If you do need to enable this option then you should select the manual option and then begin the process of including your style sheets and scripts one by one – yes it is more work, but it will help you identify problems as soon as they arrise.