• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Startup Hero

The Official Blog Of Name Hero

Learn To Fly Above The Competition Get Started
  • HomeWelcome
  • CoursesVideo Training Center
  • About UsWhat is StartupHero?
  • BlogGet the latest
  • Start HereStartup 101
  • SpeakingPodcast & Media
  • ResourcesTools to help You
    • Reselling WordPress Hosting
    • Resell Hero
    • How To Start A Blog
  • NameHeroCloud Web Hosting

Use Cloudflare Cache Rules Instead Of Page Rules

By Bhagwad Park on November 7, 2022 0

Use Cloudflare Cache Rules Instead Of Page Rules

These days, Cloudflare is putting a lot of effort into revamping its cache system. The other day, I wrote about the new Cloudflare Cache Reserve system that had infinite retention using R2 storage.  Now Cloudflare is splitting its well-known “Page Rules” system into different streams, with one stream dedicated solely to caching. Here’s how it works.

Using Cache Rules Instead of Page Cache

In your Cloudflare settings dashboard, go to “Caching -> Cache Rules,” as shown here:

Cloudflare Cache Rules Filter
Cloudflare Cache Rules Filter

As you can see, unlike Page Rules, which only allowed you to create rules based on URL patterns, Cache Rules let you filter out a lot more. For example, you can set separate caching rules for certain file formats, filter by the user agent, the referrer, and more. You’re not restricted to using only the options from the dropdown box – you can use any of the expressions allowed in the Cloudflare Fields Reference through the expression editor.

For example, the following filter applies to all PNG images:

any(http.request.headers["content-type"][*] == "image/png")

Of course, you could also filter by the “.png” filename extension. The point of the above example is to demonstrate the range of filters you can use with the Cloudflare Cache Rules. Once all the Page Rules are split into separate streams, I foresee they will vanish entirely. And why not?

Matching with “AND”/”OR” Rules

In addition to having greater control over which URLs get filtered, you can mix and match different conditions using “AND”/”OR” statements. So you can create detailed exceptions for caching. This opens up new avenues for caching. For example, you can create a cache rule for a URL and create an exception if it contains a particular query string. You can even mix this with Page Rule rewrites so that all links you click on a URL containing a certain query string will rewrite to use the same query string.

This kind of fine-grained caching is very cool!

Increased Limits for Free and Pro Tiers

The old Page Rules limit for free accounts was just three rules. With the new Cache Rules, that limit is ten for the free tier and 25 for the Pro tier. Here’s a screenshot of a free domain on Cloudflare with the new quota:

Ten Free Cloudflare Cache Rules
Ten Free Cloudflare Cache Rules

As you can see, this is a massive upgrade from what we had previously. Considering that we’ll get expanded limits for each breakdown, this represents a new level of control over the various aspects of traffic filtering, even for free users.

No Need for “Stale-While-Revalidate” Code

Earlier, I’d written about how to ensure that we serve stale content to users while refreshing content from the origin. This allows Cloudflare to delay serving fresh content just one more time while refreshing its own cache. It ensures that new content will be served as fast as old content.

With Cloudflare Cache rules, we no longer need to worry about fiddling with .htacess files. Instead, you can specify the stale-while-revalidate condition within the Cache Rules interface like this:

Serving State Content While Updating
Serving State Content While Updating

This is much easier than using a .htaccess directive that risks breaking your site. You can see from the screenshot that you can also use a bunch of other directives, such as specifying the EDGE TTL or even configuring the cache keys used to determine whether or not Cloudflare should serve separate cached content for device types and more.

Complete Caching Control

Cloudflare already had an impressive set of caching filters. But with the latest Cache Control feature it takes caching to the next level. Combined with Cache Reserve, it’s almost like having a secondary hosting provider at a fraction of the cost!

Bhagwad Park Profile Picture
Bhagwad Park

I’m a NameHero team member, and an expert on WordPress and web hosting. I’ve been in this industry since 2008. I’ve also developed apps on Android and have written extensive tutorials on managing Linux servers. You can contact me on my website WP-Tweaks.com!

Reader Interactions

Leave a Reply Cancel reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Connect With Us!

Superhero Resources

Fix Common Issues

  • How To Setup Free And Automatic SSL Certificates
  • How To Setup Cloudflare With Railgun
  • How To Fix Memory Exhausted Errors In WordPress
  • How To Edit PHP Version/Upload Limit/Add Extensions
  • How To Move/Migrate Your Business To Name Hero

Free Guides

  • How To Setup NameHero Hosting
  • How To Create A Web Hosting Business With WordPress
  • How To Start A WordPress Blog
  • How To Migrate WordPress To A VPS
  • How To Speed Test And Optimize Your WordPress Website
  • Magento 2.X Installation Guide
  • How To Clean Up A WordPress Hack

Training

Recent Posts

  • The Best WordPress Plugin To Combat Plagiarism
  • Is It Time to Bring Back Blog Comments?
  • Two Filters That No Longer Work In Gutenberg (And Workarounds)
  • Migrating To The New Cloudflare Managed Rules Interface
  • How To Sort Posts By The “Last Modified” Date
  • How To Make WordPress Send E-mail From Another Address
Subscribe in a reader
  • Web Hosting
  • WordPress Hosting
  • Reseller Hosting
  • VPS Hosting
  • Twitter
  • Facebook
  • LinkedIn
  • YouTube
  • FTC Disclosure
  • Earnings Disclosure
  • Privacy Policy

Copyright © 2023 · Smart Passive Income Pro on Genesis Framework · WordPress · Log in