I already use CloudFlare as a CDN (content delivery network) to cache my static resources and serve them closer to the visitor. CloudFlare also automatically serves content using HTTP/2 and even allows one to use Server Push feature to push resources before the browser even has received the HTML page. The last step is to cache everything at CloudFlare - the HTML pages.
Disable your existing CDN if you have one and setup CloudFlare CDN as described in my post here. I am using the free tier which limits us to 3 Page Rules to allow us to play with static HTML caching. First we setup a Page Rule to prevent caching of the admin pages of WordPress. Secondly we create a rule to prevent caching of preview pages. Lastly we create a rules to cache everything else. Replace
odd-one-out.serek.eu with your own domain.
You can tweak the above Page Rules to your liking, but the most important part in the first two rules are to set
Cache Level to
Bypass and the last rule to set
Cache Level to
Cache Everything. I also set the
Browser Cache TTL to the lowest I can and the
Edge Cache TTL to the highest.
One last problem is that the login page to WordPress is cached, to solve this I use the Rename wp-login.php plugin as recommended by this post. Make sure the login is renamed to something that begins with
wp-admin to match the first Page Rule, e.g.
The results are amazing, my average page load was around 1.5 seconds before this change, now I am around 0.5 seconds!
My server load has also been reduced dramatically since almost no requests ever hit my server again. In fact, I had to change my server monitor url to include
?preview=true in the request URL since I was receiving a cached version of my page. I did not even notice that my server had been down for several days! But then neither did my visitors.
There are a few limitations to this approach:
- When updating / changing pages and posts in WordPress I need to manually clear the cache in CloudFlare. There are WordPress plugins to clear the CloudFlare cache automatically, but when I only post once or twice a month it is not a problem
Comments are closed. If you have a question concerning the content of this page, please feel free to contact me.