Cloudflare is an integrated CDN, DNS server, Web reverse proxy Web firewall, DDoS protection service and many more, a very common name among webmasters.
However Cloudflare is mostly used as a CDN service and reverse proxy. So, checking the cache status is important to know if the Clocdflare caching mechanism is actually working or not.
Here we'll discuss about how to check the Cloudflare cache status of a URL, obviously which being served by Cloudflare.
ContentsShow / Hide
Check Cloudflare cache status
On Linux, UNIX or macOS it's very easy to check the cache status with the
The idea is to fetch the web page with any of these commands, retrieve the response header, then filter out the header with
An example below using this very site, as it relies on Cloudflare heavily.
wget -qSO /dev/null https://www.your-url.com/file1.js 2>&1 | grep -i 'CF-Cache-Status'
The output cache status could be HIT, MISSED, EXPIRED or others, here's the detailed article about the meaning of different status.
As a note, sometimes you won't get any output to show the cache status. Specially for those file types which are not normally cached by Cloudflare. As example HTML files, dynamic contents and content with query strings.
I'm using the
wget command this time. If yo're a little familiar with this command, then it should be very easy to understand the flags I'm using.
-q is to suppress the output, the
-S to show the server headers and the
-O to specify an output file, which is
/dev/null in this case.
Enjoy free shipping and One-Day delivery, cancel any time.
The exact thing could be achieved with the
cURL command, an example below.
curl -svo /dev/null https://your-url.com/ 2>&1 | grep -i 'cf-cache-status'
A shell script to do the same quickly
Well, typing a bunch of commands is not exactly handy when you've to do the same many times.
So, here's the idea of a very simple script, save it as any name you want, and make it executable.
wget -qSO /dev/null [email protected] 2>&1 | grep -i 'cf-cache-status'
I've saved it as
cf_cache_check, and the usage is simple.
chmod +x cf_cache_check
Or even better, copy it to the
/usr/local/bin/ directory after making it executable.
The script is just the beginning of an idea, you can modify it to quickly check many other Cloudflare related issues. As example, you can easily check Cloudflare SSL and HTTP/2 support with cURL.