How does Cloudflare set an eligible file's edge TTL from origin headers or defaults, and how does Browser Cache TTL change what browsers receive?
answer
- two lifetimes, edge and browser
- Origin Cache Control always on below Enterprise
- 120, 20 and 3 minutes
- Browser Cache TTL only lengthens
basics
~20 sThe edge follows the origin's s-maxage, max-age or Expires; with none, it uses status-code defaults (120 minutes for 200, 206 and 301). Browser Cache TTL, 4 hours by default, raises shorter origin lifetimes for browsers unless set to Respect Existing Headers.
solid answer
~40 sWith **Origin Cache Control**, always on for Free, Pro and Business, the edge honours the origin: `s-maxage` beats `max-age`, `max-age` beats `Expires`, bare `private` and `no-store` keep the file out of cache, and `no-cache` or `max-age=0` mean store but revalidate before every use. If the origin sends neither `Cache-Control` nor `Expires`, Cloudflare applies status-code defaults: 120 minutes for 200, 206 and 301; 20 minutes for 302 and 303; 3 minutes for 404 and 410; nothing else cached. Browsers get the origin's lifetime, adjusted by the zone's **Browser Cache TTL** (default 4 hours): Cloudflare raises a shorter or missing lifetime to the setting but never shortens a longer one, and **Respect Existing Headers** turns the override off.
go deeper
Recall that origin headers set the edge lifetime when present, that a bare 200 is cached for two hours, and that browsers get their own lifetime.
Explain Origin Cache Control's handling of s-maxage, max-age, private, no-store and no-cache, the status-code default table, and Browser Cache TTL's raise-but-never-lower rule.
Spot the production trap where the 4-hour Browser Cache TTL default stretches a short origin max-age, know that purging cannot fix it, and choose Respect Existing Headers or versioned file names.
Decide who owns freshness: origin headers per response, or zone-wide settings an operator can change without a deploy, and make the choice explicit so the two do not fight.
## Two lifetimes, set in two different ways A file served through Cloudflare can be cached in two places with two separate lifetimes: - the **edge TTL**: how long a Cloudflare data center treats its stored copy as fresh before checking with the origin; - the **browser TTL**: how long the visitor's browser may reuse its own copy, expressed in the `Cache-Control` header Cloudflare sends downstream. Without Cache Rules, the edge TTL comes from the origin's headers or from Cloudflare's status-code defaults, and the browser TTL comes from the origin's headers as adjusted by the zone's **Browser Cache TTL** setting. Neither is printed as such: Cloudflare does not expose its chosen edge TTL in a response header. ## Origin Cache Control: Cloudflare follows the origin's directives **Origin Cache Control** is the Cloudflare feature that makes the edge follow the origin's `Cache-Control` directives as the HTTP caching standard describes. It is always on for Free, Pro and Business zones and cannot be turned off there; Enterprise zones can switch it on or off with a Cache Rule. With it on, for an eligible file: - `s-maxage` sets the edge lifetime and takes precedence over `max-age` for shared caches; otherwise `max-age` applies; - if both `max-age` and `Expires` are present, Cloudflare uses `max-age`; - bare `private` or `no-store` keeps the response out of the edge cache (`BYPASS`); - `no-cache`, `max-age=0` or `s-maxage=0` do **not** mean "never store": Cloudflare stores the response and revalidates it with the origin before every use, so later requests show `REVALIDATED` or `EXPIRED`. With Origin Cache Control off (possible only on Enterprise), `no-cache`, `max-age=0` and `s-maxage=0` instead mean the edge does not cache the response at all. ## The defaults when the origin says nothing If an eligible file arrives with neither `Cache-Control` nor `Expires`, Cloudflare still caches it, using a default edge TTL chosen by the response's status code: | Status code | Default edge TTL | |---|---| | 200, 206, 301 | 120 minutes | | 302, 303 | 20 minutes | | 404, 410 | 3 minutes | | any other | not cached | So a photo returned as a bare `200` stays fresh at each data center for two hours, and a missing image's `404` is remembered for three minutes. The TTL is a **ceiling on freshness**, not a promise of retention: a rarely requested object can be evicted earlier, because retention depends on popularity and is not configurable. ## The zone's Browser Cache TTL setting Under **Caching > Configuration**, the Browser Cache TTL setting decides what lifetime browsers are told. Its default value is 4 hours, and it behaves asymmetrically: 1. If the origin's `Cache-Control` or `Expires` lifetime is **shorter** than the setting, Cloudflare overrides it with the setting's value. 2. If the origin sends **no** `Cache-Control` or `Expires`, Cloudflare inserts the setting's value. 3. If the origin's lifetime is **longer**, it is left alone: the setting can lengthen browser caching but never shorten it. 4. **Respect Existing Headers** tells Cloudflare not to override or insert anything, passing the origin's `Cache-Control` through. With Origin Cache Control on, a `private` directive from the origin is preserved when the setting applies. ## A news-site trap A news site serves `/static/live-ticker.js` with `Cache-Control: max-age=60`, expecting browsers to pick up a new ticker script within a minute. With Browser Cache TTL at its 4-hour default, 60 seconds is shorter than the setting, so browsers receive a 4-hour lifetime and keep the old script long after the origin changed it. Purging Cloudflare's cache does not help: it never reaches copies already held in browsers. The fix is to set Browser Cache TTL to **Respect Existing Headers** (or to a value no longer than the shortest lifetime the site relies on), and to give fast-changing scripts versioned file names. ## Reading the result Because the edge TTL is not printed, a team infers it from behaviour: - `cf-cache-status: HIT` with an `Age` header that keeps growing means the copy is still fresh at that data center; - once `Age` would pass the lifetime, the next request shows `EXPIRED`, `REVALIDATED` or, with `stale-while-revalidate`, `UPDATING`; - the `Cache-Control` a browser receives shows the browser TTL after the Browser Cache TTL setting has been applied, which may differ from what the origin sent. Comparing the origin's raw headers with what arrives through the proxy is the quickest way to see whether the setting rewrote them. ## When the defaults are not enough The zone-wide behaviour above covers what Cloudflare does unprompted. Overriding the edge lifetime for particular paths, ignoring the origin's headers, or setting TTLs per status code is the job of a Cache Rule's Edge TTL and Browser TTL settings, a separate subject covered with Cache Rules.
- On an Enterprise Cloudflare zone, how does turning Origin Cache Control off change the handling of Cache-Control: no-cache?With Origin Cache Control on, `no-cache` means Cloudflare stores the response and revalidates it with the origin before every use. With it off, which only Enterprise zones can choose, `no-cache`, `max-age=0` and `s-maxage=0` mean the edge does not cache the response at all, and visitors are served from the origin every time.
- Why does a 404 for a deleted image keep returning from Cloudflare for a few minutes after the image is restored on the origin?With no `Cache-Control` or `Expires` on the 404, Cloudflare applies its status-code default and caches 404 and 410 responses for 3 minutes. Until that copy expires, the data center keeps answering 404. Sending `Cache-Control: no-store` on error responses, or a shorter `max-age`, changes it.
- Can a team see Cloudflare's chosen edge TTL in a response?Not directly: the edge TTL is not exposed in response headers. What you can see is the origin's `Cache-Control` as forwarded, the `Age` header on `HIT`, `STALE` and `UPDATING` responses, and the status moving to `EXPIRED`, `REVALIDATED` or `UPDATING` once the copy goes stale.
- Without Cache-Control from the origin, Cloudflare never caches anything.
- Cache-Control: no-cache stops Cloudflare from storing the file on every plan.
- Browser Cache TTL can shorten a longer max-age sent by the origin.
- The edge TTL and the browser TTL are always the same number.
- Purging Cloudflare's cache also clears copies already held in visitors' browsers.