Subscribe for news, tips, and recommendations to use on your website today!

<p>Thanks so much. You'll receive our new articles via email as they are published.</p>


Boost website performance, eliminate server load, using Cloudflare’s Page Rules

Boost website performance, eliminate server load, using Cloudflare’s Page Rules

Many website owners use the amazing and free Cloudflare CDN (content delivery network), which caches static files (images, javascript, CSS) in all 28 data centers around the world, while also providing a layer of security and traffic scanning/blocking. The result is faster load times for your web site, and lessened possibility of a hacked or attacked website.

Most website owners also enable server-side caching, with WordPress sites usually using W3 Total Cache, WP Super Cache, Hyper Cache, or other popular plugins. These plugins lessen the server load by serving non-dynamic flat HTML that is generated by WordPress, and requests for the same URL that is already available as HTML is served without needing it to execute any of the PHP code or MySQL database queries that are usually involved in every page load.

What most website owners don’t know is that there is a simple way built right into Cloudflare, using Page Rules, that can also cache not only static files, but the very same HTML files right on the Cloudflare CDN, so there are no requests to the web server for any number of page requests – only when refreshing the cache will Cloudflare hit the web server. This will boost your website performance even more, because it’s not dependent on any response from your web server – and shared hosting is very common to have higher first-byte response times, simply due to the number of accounts most web hosts put on a single server. You can still use other caching plugins to help performance when refreshing the Cloudflare full-page HTML cache. Be aware that Cloudflare’s normal caching under the caching tab does not have the “Cache Everything” option, only Page Rules offer that option on a URL pattern.

Please note, for websites running WordPress, you must create a rule that also tells Cloudflare not to cache the HTML from the /wp-admin/ administrator area or /wp-login.php login form, otherwise the administrator dashboard and login form will have issues.

So here’s the steps and two exact rules to add to Cloudflare’s Page Rules that we’ve tested and work great with WordPress, please enjoy and share!

  • Log into Cloudflare. Next to your domain name(s), click the drop-down box, and click on Page Rules
  • To set up the first rule for the WordPress Admin area and login form, in the rule pattern box, type in “*domain.com/wp-*”, and be sure to set Rocket Loader to Off, as it will usually break features of your site that rely on jQuery and other javascript libraries. Everything else can be left at the default values, or adjust based on your usual Cloudflare settings. Click Add Rule.
  • Now, set up as the very last rule so it runs after all other rules, the rule for HTML caching of the rest of the site. In the rule pattern box, type in “*domain.com/*” and then Custom Caching, choose the magic option “Cache Everything”. This sets Cloudflare to cache the HTML as well as usual static files! Then, set the Browser Cache Expire TTL to 30 mins or 1-2 hours. This will allow Cloudflare to refresh it’s cache across all it’s edge servers, so edits take effect within that time. Again, be sure to set Rocket Loader to Off. Click Add Rule.

That’s it! You’ve just boosted your website performance, and virtually eliminated your web server load to near-zero, no matter how much traffic is hitting your website. Your search engine rankings could be improved, your web hosting costs could be reduced (if based on traffic/bandwidth/visits or CPU), and your visitors are more likely to stick around longer and share your content, based on your site consistently loading faster and without any delays.

If you run into any issues, remove the cache everything rule, or try adding additional rules above it (giving it a higher priority) to exclude other areas of your website, like “*domain.com/shop/*” for e-commerce areas, etc. All dynamic, always changing content areas should have exclusions added for them.

The free plan allows for up to three page rules. The Pro plan allows for up to 20 rules, and adds SSL support using their wildcard certificate, so that’s the plan for most businesses. Cloudflare also often proactively offers filtering of WordPress vulnerabilities in their Web Application Firewall (WAF), making their service even more valuable, and has a quick and easy sign up, give them a try and let us know how it works for you. These aren’t affiliate links, it’s just a highly recommended service.

We hope you enjoy and faster website, and share this tip with your friends and colleagues.


Rob Marlbrough

  1. Thanks for the great write-up. We recently created a new page that contains video tutorials for some of the most popular/recommended page rules.

    https://www.cloudflare.com/features-page-rules/

    You will also soon be able to purchase additional page rules without changing plan type. 🙂

  2. Ash Scott Says: August 29, 2016 at 2:14 pm

    This has helped a few of my clients save their bandwidth on their VPS’. Super article. Cheers Rob!

  3. Thanks for the article but I am curious.

    Why did you set up a page rule for “*domain.com/*”.

    You can define the Browser Cache Expiration under the “Cache” tabs which I assume is applicable to the whole site. So this page rules doesn’t make sense. Can you clarify?

    • Hi there. I’ve added a clarifying sentence to the post:

      Be aware that Cloudflare’s normal caching under the caching tab does not have the “Cache Everything” option, only Page Rules offer that option on a URL pattern.

      Hope this clarifies using the Page Rules for the full HTML “cache everything” speed boost.

      Rob

Leave a Reply

Your email address will not be published. Required fields are marked *