Check Cloudflare Cache Status

Check if a resource is served from Cloudflare's cache by inspecting the CF-Cache-Status header.

Code

General
const response = await fetch(url);
return response.headers.get('CF-Cache-Status') || 'No CF-Cache-Status header';

Parameters

URL to check

Browser·fetch() may be limited by CORS

CF-Cache-Status Values

StatusMeaning
HITServed from Cloudflare cache
MISSNot in cache, fetched from origin
EXPIREDWas cached but has expired, refetched
STALEServed stale while revalidating
DYNAMICNot eligible for caching (e.g., POST requests, dynamic content)
BYPASSCache bypassed due to configuration

Real-World Usage

async function checkCFCache(url) {
  const response = await fetch(url);
  const status = response.headers.get('CF-Cache-Status');
  const age = response.headers.get('Age');

  return {
    cached: status === 'HIT',
    status,
    age: age ? parseInt(age) : null
  };
}

Testing with httpbin

Use httpbin to simulate different cache statuses:

  • https://httpbin.org/response-headers?CF-Cache-Status=HIT
  • https://httpbin.org/response-headers?CF-Cache-Status=MISS
  • https://httpbin.org/response-headers?CF-Cache-Status=EXPIRED

More JavaScript Snippets