When you use Cloudflare as your website CDN server, you always need to know whether the web page is cached by Cloudflare or not. And Cloudflare returns some HTTP response headers when you request the web page, you can get the web page cached status from those response headers.
One of the response headers is Cf-Cache-Status, this header’s value shows whether the web page is cached by Cloudflare or not. The header value can be DYNAMIC or HIT. This article will tell you how to change the response header Cf-Cache-Status‘s value from DYNAMIC to HIT.
1. How To Inspect HTTP Response Header Cf-Cache-Status’s Value.
- You can use google chrome inspector to get the current web page response header’s value.
- Just open your web page in google chrome, right-click the web page area, then click Inspect menu item in the popup menu list.
- Click the Network tab in the inspector window, and reload the web page again.
- Click the resource name ( for example www.dev2qa.com or any web resource URL) on the inspector window Network tab left side, click Headers tab on the right panel, then you can see the resource request and response headers list.
- Expand the Response Headers section by clicking the arrow icon before the Response Headers section, then you can scroll to find the cf-cache-status response header and it’s value.
- You can read the article How To View HTTP Headers, Cookies In Google Chrome, Firefox, Internet Explorer for more detail.
2. What Dose Cf-Cache-Status Header’s Value Means.
- Below is the Cf-Cache-Status Header’s Value list.
- HIT: The web resource ( HTML page, image, js, etc) has been cached in the Cloudflare server and not expired. It is returned from the cache.
- MISS: The web resource has not been found in the Cloudflare cache, Cloudflare gets the resource from your original web server, puts it in the Cloudflare cache, and returns it to the web browser.
- EXPIRED: The cached web resource has expired, so Cloudflare will retrieve this web resource from your original web server again, put it in Cloudflare cache and return it to the web browser.
- BYPASS: The returned web resource is not cached and will not be cached, it is retrieved from the original web server directly.
- DYNAMIC: The web resource is returned from the original web server, it is not cached by Cloudflare by default. But you can configure Cloudflare to cache such web resources, then in the future request, the web resource will be cached.
3. Inspect Web Resource Response Header Cf-Cache-Status Value.
- By default, Cloudflare will not cache the HTML web page.
- So when you inspect the web page follow section 1’s steps, you will find a response header like cf-cache-status: DYNAMIC.
- But when you inspect other web resources ( for example js, image files, etc), the response header may be cf-cache-status: HIT or cf-cache-status: MISS, etc. This is because Cloudflare will cache such web resources by default.
4. How To Configure Cloudflare Page Rule To Change Web Page Response Header Cf-Cache-Status’s Value From DYNAMIC to HIT.
- What you need to do is just add a page rule in Cloudflare settings to make your web page being cached by Cloudflare.
- Log in to your Cloudflare management dashboard.
- Click the Rules icon on the page top area.
- Click Create Page Rule button.
- Input a url path ( for example www.abc.com/def* ) in the top input text box, you can use * in the url path.
- Select Cache Level in Pick a Setting drop-down list.
- Select Cache Everything in the Select Cache Level drop-down list.
- Click the Save and Deploy button to save and deploy the changes.
- You can select page rule trigger order in the Order selection list.
- If there are multiple page rules, the most top page rule in the page rule list will be triggered first.
- Now when you browse the Html page in the page rule url path, you will find the response Cf-Cache-Status header’s value will change to HIT or MISS.