How to determine if a site uses Cloudflare cache with curl

Why would you want to know if a site is using Cloudflare cache? If you are debugging or responding to an incident, it is easy to forget that Cloudflare might be caching a site and it will hamper your efforts. Since most hosts cache, you’ll be dealing with a host/CDN cache, Cloudflare cache, and local browser cache. Knowing how to purge or bypass those is important.

So, how can you tell if a site is using Cloudflare cache? Good news: Cloudflare returns a specific header for sites using their cache: cf-cache-status

You can check for it with curl!

curl -sI | grep "cf-cache-status"

the -sI option there means “silent” and “headers only.

You might notice some different values attached to that cf-cache-status header: DYNAMIC, HIT, MISS, etc. You can learn about those here:

Default Cache Behavior · Cloudflare Cache docs
Cloudflare makes customer websites faster by storing a copy of the website’s content on our servers. Caching static resources at Cloudflare reduces your server load and bandwidth, with no extra charges for bandwidth spikes

It is worth noting that the cache response you get for the homepage is not necessarily the same response you’ll get for other pages and assets on the site, but the presence of the header is a dead giveaway.

If you support a lot of sites like we do at work, you can script it with bash and get a neat list of which ones use Cloudflare cache:

for url in $(head -n800 urls.txt); do
    content="$(curl -sI $url | grep "cf-cache-status")"
    if test -z "$content"
        echo "$url || $content" >> cloudflare.txt

This assumes a file named urls.txt with one URL per line. It runs the curl command for each URL and only outputs a result in the text file (cloudflare.txt) if the grep is not empty.

Leave a Reply

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

%d bloggers like this: