For years now I have loved WordPress and used it to power just about every site I build. It is however a very heavy system and doesn’t run at its best out of the box. It has taken years but I have now perfected my speed optimisations on WordPress using W3 Total Cache and CloudFlare. Below is a outline of the setup with more details to be released in future posts as I write them.
The first step to making WordPress run fast is a good server. I am currently using Nginx web server natively with no Apache in sight on a 4 core Digital Ocean VPS with 8GB if RAM (currently around 40 sites on the server). In front of this I use CloudFlare for caching and DNS.
CloudFlare plays a key role in this as you will see going forward. CloudFlare not only caches my static content but also the HTML for brochure style content sites with no special functions. This means my server will not even be involved in the requests for busy websites with everything coming off the edge location on the CloudFlare network.
The final piece of the puzzle is W3 Total Cache, a very powerful plugin if you know what you are doing. This is also what allows me to purge the CloudFlare cache when pages within WordPress are changed.
CloudFlare Page Rules for Extreme Speed
The free plan on CloudFlare allows 3 page rules which is enough for brochure style sites and blogs like this site. We are going to create 2 rules to tell CloudFlare how to cache our site.
- Cache everything
- Don’t cache WP Admin
Assuming you have already added your domain to CloudFlare and changed your name servers this step is very easy. Navigate to your site on CloudFlare and click the Page Rules tab across the top.
Click ‘Create Page Rule’ and enter ‘
yourdomain.com/*‘ . Then click ‘Add a Setting’ and select the options as shown below before pressing save and deploy.
Next we need to create a new rule that will reduce the caching level of key WordPress pages and WP Admin. Click Create Page Rule 1 more time. and enter the settings as shown below
It is important that this rule is number 1 on your list. If it is not simply drag and drop to reorder the list.
Optimising W3 Total Cache
This is where things get a lot more complicated. W3 Total Cache is a very powerful plugin, however, that means it has a lot of settings and options some of which can break stuff. If you don’t know what you are doing at this point I recommend getting a professional to help configure the plugin for your site.
First install the plugin from the WordPress repository. Once installed you will need to do you standard caching settings for HTML caching as a minimum.
Now under Performance on the WP Admin menu click extensions and enable CloudFlare. The click settings next to CloudFlare. It is here where I am going to focus on the exact settings I use and recommend you do the same.
The above setting is by far the most important here. It is this setting that will allow you changes to be seen without waiting 7 days for the CloudFlare cache to expire. With this checked every time you save a page W3 Total Cache will send a request to CloudFlare to purge that page from its global cache and force the new version to be cached the next time the page is loaded.