When an origin behind Cloudflare sends Cloudflare-CDN-Cache-Control, CDN-Cache-Control and Cache-Control together, which decides edge caching, and which reach the browser?
answer
- most specific header wins
- one of them never leaves Cloudflare
- Browser Cache TTL touches only one
- no-store there still bypasses
basics
~10 sCloudflare-CDN-Cache-Control decides first, then CDN-Cache-Control, then Cache-Control. Cloudflare-CDN-Cache-Control is never forwarded; CDN-Cache-Control and Cache-Control are, and Browser Cache TTL rewrites only Cache-Control.
solid answer
~40 sFor its own caching decision Cloudflare reads `Cloudflare-CDN-Cache-Control` first, then `CDN-Cache-Control`, and only then `Cache-Control`; when a CDN header is present, `Cache-Control` passes through untouched and `Expires` is ignored for the decision. `Cloudflare-CDN-Cache-Control` is consumed at the edge and never forwarded, while `CDN-Cache-Control` is forwarded for any CDN further down, and the zone's Browser Cache TTL rewrites only `Cache-Control`. `no-store` or bare `private` in either CDN header gives `BYPASS` even under `Cache-Control: public`. A Cache Rule's Edge TTL override, or a Cache Response Rule setting directives, outranks all three. Because the Cloudflare-only header is invisible downstream, an unexplained `BYPASS` means reading the origin's raw headers.
go deeper
Recall that Cloudflare can be given its own caching header, separate from what browsers read.
Explain the precedence order, which header is forwarded and which is not, and that Browser Cache TTL only rewrites Cache-Control.
Debug an unexplained BYPASS by reading origin headers directly, and prefer a Cloudflare-only lifetime over s-maxage when stale-while-revalidate matters.
Decide where edge lifetimes live: in origin headers versioned with the code, or in Cloudflare rules an operator can change, and keep one source of truth.
## Three headers, one decision An origin behind Cloudflare can address caches in up to three response headers: - `Cache-Control`: the standard header, read by browsers and every cache on the path; - `CDN-Cache-Control`: aimed at CDNs, so they can be told something different from browsers; - `Cloudflare-CDN-Cache-Control`: aimed at Cloudflare alone. The last two take the same directives as `Cache-Control` (`max-age`, `s-maxage`, `no-store`, `private`, `stale-while-revalidate`, `stale-if-error` and the rest). What makes them useful on Cloudflare is how the edge **ranks** and **forwards** them. ## Precedence for Cloudflare's caching decision Cloudflare reads the most specific header present and ignores the rest for its own decision: `Cloudflare-CDN-Cache-Control` > `CDN-Cache-Control` > `Cache-Control` - If `CDN-Cache-Control` is present, Cloudflare caches by it; `Cache-Control` is proxied as-is and does not affect Cloudflare's decision. - If both CDN headers are present, Cloudflare looks only at `Cloudflare-CDN-Cache-Control`. - `Expires` does not affect the decision while either CDN header is in use. - Two Cloudflare settings sit above all three: a Cache Response Rule that sets `Cache-Control` directives wins over both CDN headers, and a Cache Rule's Edge TTL that ignores origin headers overrides them. Both are rule settings covered with Cache Rules. ## What is forwarded downstream | Header | Used for Cloudflare's decision | Forwarded to the client | |---|---|---| | `Cloudflare-CDN-Cache-Control` | Yes, first | **No** | | `CDN-Cache-Control` | Yes, if the first is absent | Yes, for any CDN further down the path | | `Cache-Control` | Only if neither CDN header is present | Yes | The zone's **Browser Cache TTL** setting modifies only `Cache-Control`. It never rewrites `CDN-Cache-Control` or `Cloudflare-CDN-Cache-Control`. ## Directives that refuse storage The CDN headers can block caching just like `Cache-Control`. If either carries `no-store` or a bare `private`, the response is `BYPASS`, even when `Cache-Control` says `public, max-age=3600`. Softer directives do not bypass: `no-cache`, `max-age=0` or `s-maxage=0` in them give `MISS` on the first request and then `REVALIDATED` or `EXPIRED`. Sending `Cloudflare-CDN-Cache-Control` also switches **Origin Cache Control** on for that response, even on an Enterprise zone where it is off. One consequence: Cloudflare applies its `Authorization` rule: for a request carrying that header, only `s-maxage`, `must-revalidate` or `public` let the response be stored, and other directives give `BYPASS`. ## A debugging trap Because `Cloudflare-CDN-Cache-Control` is never forwarded, it is invisible in the response a developer inspects through the proxy. A file can show `BYPASS` with a perfectly cacheable `Cache-Control` and no visible reason. When that happens, read the headers at the origin directly, or have the origin drop the header and retest. ## A worked example for a news site The site wants Cloudflare to keep article images for a day, browsers to recheck them after a minute, and Cloudflare to serve a stale image while it refreshes in the background: ```http Cache-Control: public, max-age=60 Cloudflare-CDN-Cache-Control: max-age=86400, stale-while-revalidate=300 ``` - The edge treats each image as fresh for 24 hours and, after expiry, serves the stale copy with `UPDATING` for up to five minutes while it revalidates. - Browsers receive only `Cache-Control: public, max-age=60`, provided the zone's Browser Cache TTL is set to **Respect Existing Headers**; at the 4-hour default the setting would raise that 60 seconds. - Using `s-maxage=86400` in `Cache-Control` would also give the edge a day, but `s-maxage` implies `proxy-revalidate`, which stops Cloudflare from serving stale content, so the `UPDATING` behaviour would be lost. ## When none of the three is sent If the origin sends no `Cloudflare-CDN-Cache-Control`, no `CDN-Cache-Control` and no `Cache-Control`, cacheable files fall back to Cloudflare's general defaults: an eligible `200`, `206` or `301` is kept for 120 minutes, a `302` or `303` for 20 minutes, a `404` or `410` for 3 minutes, and other status codes are not cached. Browsers then receive the zone's Browser Cache TTL value, unless that setting is Respect Existing Headers, in which case nothing is inserted. ## Checking what Cloudflare obeyed - Fetch the file from the origin directly and list every caching header it sends, including the ones the proxy will hide. - Fetch it twice through Cloudflare from the same location and read `cf-cache-status` and `Age`. - If the status contradicts the visible `Cache-Control`, the answer is almost always a CDN header, a Cache Rule or a Cache Response Rule ranked above it; Cloudflare Trace shows which rules matched. ## When to choose which 1. Use `Cloudflare-CDN-Cache-Control` when only Cloudflare should behave differently and nothing downstream should see the instruction. 2. Use `CDN-Cache-Control` when there is another CDN between Cloudflare and visitors that should follow the same CDN-only instruction. 3. Send both when Cloudflare and that downstream CDN should each get their own lifetime: Cloudflare reads its own header and forwards `CDN-Cache-Control`.
- Why might a Cloudflare zone show BYPASS on an image whose visible Cache-Control is public, max-age=3600?The origin may also send `Cloudflare-CDN-Cache-Control: no-store` (or bare `private`). Cloudflare ranks that header first and never forwards it, so the refusal is invisible through the proxy. Read the headers at the origin directly, or have the origin drop the header and retest.
- On a Cloudflare zone, why use Cloudflare-CDN-Cache-Control with stale-while-revalidate instead of s-maxage in Cache-Control?`s-maxage` implies `proxy-revalidate`, which forbids Cloudflare from serving stale content, so expired objects would show `EXPIRED` while visitors wait for the origin. A Cloudflare-only header can give the edge a long `max-age` with `stale-while-revalidate`, so it serves `UPDATING` and refreshes in the background, while browsers keep their own short `Cache-Control`.
- Cache-Control always wins because it is the standard header.
- Cloudflare forwards Cloudflare-CDN-Cache-Control so browsers can see it.
- Browser Cache TTL rewrites CDN-Cache-Control too.
- no-store in CDN-Cache-Control is ignored when Cache-Control says public.
- Edge TTL in a Cache Rule cannot override the CDN headers.