CloudFlare Page Rules for Fast Loading Times
Web Tech Gadgetry has always been a long time advocate of MaxCDN. That all changed after conducting some clever experiments with CloudFlare’s page rules and their aggressive caching parameters. In this tutorial we will guide you through some CloudFlare page rules for fast loading times on your WordPress blog or website.
Using the combination of a WordPress plugin (yes, this tip only works with WordPress) and some cleverly tailored page rules via CloudFlare’s control panel, we found that we could achieve page loading times equal to or greater than that of having a proprietary CDN. This isn’t to say that there aren’t other CDN options out there that can offer better performance – rather CloudFlare is completely free.
Configuring Page Rules
If you haven’t already disabled caching for the WordPress admin you will probably want to do so now or else you may run into some erratic behaviour. I have posted an example below:
Once you have implemented the above we will now go ahead and configure CloudFlare’s most aggressive cache setting such that all aspects of your site is cached including HTML. As with before I have provided an example below:
Unfortunately doing the above on its own will result in quite a few problems when used in conjunction with a dynamic site. From this point onwards if you were to add a new post, edit an existing post or either if a user were to comment the changes wouldn’t show up until the cache had been purged. This is were a plugin comes in handy.
Luckily for us someone has taken the liberty to develop a plugin which will automatically purge the cache when a change is made to your site, whether it be due to a user commenting or a new post being published. The plugin in question is known as Sunny and I highly recommend users of WordPress and CloudFlare install it.
During the setup process you will need to provide a CloudFlare API key – which can be found on your dashboard. Once installed we suggest you configure Sunny as shown below:
This page speed tip was based off of my CloudFlare page speed experiment, referencing the performance gains of using CloudFlare and its page rules effectively.
We used the above configuration up until we enabled flexible SSL. As a result we had to use one of our page rules to redirect all requests through HTTPS. Bear in mind that free accounts are limited to just three page rules only – use them wisely.