In Cloudflare Cache Rules, how do you make a shop's anonymous HTML product pages cacheable, and what do Edge TTL and Browser TTL change?
answer
- a request-time decision per rule
- HTML sits outside the default list
- Eligible for cache versus Bypass cache
- respect, override or bypass by default
- edge copy apart from browser copy
basics
~20 sCreate a Cache Rule whose expression matches only the product paths and set it to Eligible for cache, which makes HTML cacheable. Edge TTL decides how long Cloudflare's edge keeps a copy; Browser TTL decides the lifetime sent to visitors' browsers.
solid answer
~40 sHTML is not among Cloudflare's default cached extensions, so a product page goes to the origin every time until a **Cache Rule** says otherwise. Write an expression such as `starts_with(http.request.uri.path, "/products/")` and choose **Eligible for cache**; matching responses become cache candidates whatever their extension, while **Bypass cache** does the opposite. **Edge TTL** has three modes: follow the origin's `Cache-Control` and fall back to Cloudflare's defaults (`respect_origin`), follow it and skip caching when it is absent (`bypass_by_default`), or ignore it and use a fixed TTL (`override_origin`), plus optional per-status-code TTLs. **Browser TTL** separately sets what browsers are told: respect origin, override, or bypass. The shortest Edge TTL you can set is 2 hours on Free, 1 hour on Pro and 1 second on Business and Enterprise.
go deeper
Recall that HTML is not cached by default and that a Cache Rule set to Eligible for cache is how you change that for chosen paths.
Explain the three Edge TTL modes by what they do when the origin does or does not send Cache-Control, and keep Browser TTL separate from the edge lifetime.
Show you would keep respect_origin on HTML so origin private and Set-Cookie still protect personal pages, and reserve override_origin for paths that can never be personal.
Frame the choice of Edge TTL mode as who owns cache lifetimes: the edge configuration or the application's headers, and what each costs when someone gets it wrong.
## Why a product page is not cached until a rule says so Cloudflare caches a fixed list of static file extensions by default (images, stylesheets, scripts, fonts, archives and similar), and **HTML is not on it**. A request for `/products/blue-kettle` therefore goes straight to the origin, and the response shows that Cloudflare judged it not eligible for cache. To cache a shop's anonymous product pages you need a **Cache Rule**: a rule in the zone's `http_request_cache_settings` phase whose action, `set_cache_settings`, changes cache settings for the requests its expression matches. A few facts frame every Cache Rule: - Cache Rules work only for hostnames whose DNS records are **proxied** through Cloudflare. - They exist on every plan; a zone can hold **10** rules on Free, **25** on Pro, **50** on Business and **300** on Enterprise. - They can be created in the dashboard, through the Rulesets API, or as code against that API. ## Writing the expression and choosing eligibility The expression is written in the Rules language. Fields that matter for a shop include: - `http.host`, the hostname of the request; - `http.request.uri.path`, the path, often tested with `starts_with()`; - `http.request.uri.path.extension`, the lowercased extension without the dot; - `http.cookie`, the whole `Cookie` header as one string, on every plan; - `http.request.cookies`, the cookies as a map keyed by name, on Pro and above. A rule for product and category pages could read `(http.host eq "shop.example.com" and (starts_with(http.request.uri.path, "/products/") or starts_with(http.request.uri.path, "/c/")))`. Under **Cache eligibility** there are two choices: - **Eligible for cache**: Cloudflare attempts to cache matching responses whatever their extension. This is the behaviour Page Rules called Cache Everything, and it is what makes HTML cacheable. - **Bypass cache**: matching requests are not cached and go to the origin without a cache lookup. Eligible for cache makes a request a **candidate**; it does not force storage. Whether the response is stored, and for how long, depends on the Edge TTL mode. ## Edge TTL: how long the edge keeps a copy | Dashboard option | API `edge_ttl.mode` | Origin sends `Cache-Control` | Origin sends none | |---|---|---|---| | Use cache-control header if present, use default Cloudflare caching behavior if not | `respect_origin` | follow it | Cloudflare's default TTL for that status code | | Use cache-control header if present, bypass cache if not | `bypass_by_default` | follow it | do not cache | | Ignore cache-control header and use this TTL | `override_origin` | ignored | cache for the rule's TTL | **Status Code TTL** adds per-status values (one code, a range, or greater or less than a code). For those statuses it ignores the origin's `Cache-Control`, as `override_origin` does. The shortest Edge TTL a zone can set depends on its plan: 2 hours on Free, 1 hour on Pro, 1 second on Business and Enterprise. `respect_origin` is the safe default for HTML. With it, an origin that sends `Cache-Control: private` or `no-store`, or a `Set-Cookie` header, keeps that response out of the edge cache, so the application stays in charge of what is personal. `override_origin` removes that protection: it ignores `private` and `no-store`, and when the origin sets a cookie Cloudflare strips the `Set-Cookie` header and stores the page. Use it only where the expression can never match a personal page. ## Browser TTL: what visitors' browsers are told **Browser TTL** is a separate setting (`browser_ttl` in the API) with three modes: respect origin, override origin with a duration you pick, or bypass. Overriding changes the lifetime Cloudflare passes downstream to browsers; it does not change how long the edge keeps its own copy. For product pages, a short browser lifetime with a longer edge lifetime is the usual pairing: a price change can be cleared from the edge at once, while purging the edge never reaches copies already held in browsers. ## Other settings on the same rule - **Cache Key**: what identifies the stored copy (query string handling, Cache Deception Armor, device type). - **Serve stale content while revalidating**: `serve_stale.disable_stale_while_updating` stops Cloudflare serving the expired copy while it fetches a fresh one. - **Respect Strong ETags**, **Origin error page pass-through** and **Cache Reserve eligibility** also live here. ## Checking that it works 1. Deploy the rule, or save it as a draft and review it first. 2. Request a product page twice with `curl -sI` and read `cf-cache-status`: the first response in a data center is usually `MISS`, the next `HIT`, carrying an `Age` header. 3. A `BYPASS` means the request was eligible but the origin's response was not cacheable, for example `private` or `Set-Cookie` under `respect_origin`; a `DYNAMIC` means the request was not eligible at request time: the rule did not match, or a later Bypass cache rule did. 4. Use Cloudflare Trace on the URL to see which Cache Rules matched and which settings they applied.
- Why can a product page still show BYPASS after an Eligible for cache rule matches it?The rule made the request a candidate, but the response decided otherwise. Under `respect_origin`, an origin `Cache-Control: private` or `no-store`, a `Set-Cookie` header, `Vary: *`, or a body above the plan's size limit keeps it out of cache. Fix the origin's headers on anonymous pages rather than switching to `override_origin`, which would also store any personal page the expression catches.
- When would you choose bypass_by_default for a Cache Rule's Edge TTL?When the origin team sets an explicit `Cache-Control` on everything it wants cached and you want anything without one kept off the edge. Caching becomes opt-in per response: a page sent with `public, max-age=600` is stored, while a route that forgot the header is not cached at all instead of getting Cloudflare's default status-code TTLs.
- Eligible for cache forces every matched response into the cache whatever the origin sends.
- Cloudflare caches HTML by default, so product pages need no Cache Rule.
- An override_origin Edge TTL is safe on a whole hostname because Set-Cookie responses are never cached.
- Browser TTL controls how long Cloudflare's edge keeps its copy of the page.
- Cache Rules are an Enterprise-only feature.