Cache-Control vs. Cloudflare Page Rules: Your Headers Are Lying to You
I spent two hours debugging a caching problem that turned out to be Cloudflare quietly ignoring my Cache-Control headers. Here's what's actually happening at the edge.
Cloudflare's caching behavior is not what you think it is if you're coming from a "headers are law" mental model. I had that model for years, and it burned me on a client project badly enough that I went and read the actual Cloudflare documentation instead of assuming I understood it.
The short version: Cloudflare has its own opinions about what gets cached, and your Cache-Control headers are more like suggestions than commands - at least by default.
What I Expected vs. What Actually Happens
Most of us learn HTTP caching through the RFC. You set Cache-Control: public, max-age=3600 on a response, and caches - proxies, CDNs, browsers - respect it. That's the contract.
Cloudflare respects part of that contract. The part it quietly bends is around what it's willing to cache in the first place.
By default, Cloudflare only caches static assets based on file extension. HTML pages? Not cached at the edge, regardless of your Cache-Control headers. JSON API responses? Also not cached by default. PHP-generated pages with Cache-Control: public, max-age=86400? Cloudflare passes them straight through to your origin on every single request.
I learned this debugging a performance issue for a real estate client. They had property listing pages that were fully cacheable - same content for every visitor, rebuilt every 15 minutes from an MLS feed. I'd set Cache-Control: public, s-maxage=900 on those responses. Cloudflare's analytics showed a cache hit rate of 0%. Every request was hitting the origin server. The headers were correct. Cloudflare just wasn't acting on them because the URL ended in /listings/seattle/ and not .jpg.
The Default Caching Behavior You Need to Understand
Cloudflare's default cache behavior is controlled by what they call "Cloudflare Cache Rules" (previously, and confusingly, overlapping with "Page Rules"). The key concept is the Cache Level.
At the "Standard" cache level, Cloudflare caches based on a built-in list of cacheable file extensions: images, CSS, JS, fonts, and so on. It does not cache HTML or dynamic content by default, even if you send Cache-Control: public.
The s-maxage directive does influence how long Cloudflare caches something - but only if Cloudflare has decided to cache it in the first place. If the content type or URL pattern falls outside Cloudflare's default "cache this" list, s-maxage is ignored at the edge entirely. The browser still sees and respects your headers. The CDN layer does not.
Here's a simple diagnostic: add CF-Cache-Status to your response headers logging. Cloudflare injects this header on every response. The values you'll see:
HIT- served from Cloudflare's cacheMISS- not in cache, fetched from originEXPIRED- was cached, but TTL passedBYPASS- Cloudflare deliberately skipped the cacheDYNAMIC- Cloudflare decided this content is dynamic and won't cache it
If you're seeing DYNAMIC on responses where you've set Cache-Control: public, that's the problem. Cloudflare made a unilateral decision.
How to Actually Control This
There are two main tools: Cache Rules (the modern approach) and Page Rules (older, being phased out but still widely used). I'll cover both because you're going to run into Page Rules on existing setups.
Cache Rules (Modern)
In the Cloudflare dashboard under Caching > Cache Rules, you can create rules that override Cloudflare's default behavior for specific URL patterns.
To cache all responses from your origin that send Cache-Control: public, you'd create a rule like:
- When:
Hostname equals yourdomain.com AND URI Path matches regex ^/listings/ - Cache eligibility: Eligible for cache
- Edge TTL: Use cache-control header if present, otherwise use default
That last option is what you want if you're managing TTLs from your application layer. It tells Cloudflare: "trust my Cache-Control and s-maxage headers for how long to hold this."
If you don't set that and just mark something as "eligible for cache," Cloudflare uses its own default TTL - which might be longer or shorter than you want.
Page Rules (Legacy, But You'll See It)
Page Rules let you set "Cache Level: Cache Everything" for a URL pattern. This is the older way to accomplish the same thing. If you're inheriting a client's Cloudflare setup, there's a good chance someone has half-configured this somewhere:
URL: yourdomain.com/listings/*
Setting: Cache Level = Cache Everything
Setting: Edge Cache TTL = 15 minutes
The problem with Page Rules is the Edge Cache TTL setting. If you set it here, it overrides your Cache-Control: s-maxage header. So if your app sends s-maxage=60 but the Page Rule says "Edge Cache TTL: 1 hour," Cloudflare caches for an hour. Your header is ignored for the CDN layer. The browser still sees s-maxage=60 and respects that. You end up with the browser caching for 1 minute and the CDN caching for 60 minutes, which is usually backwards from what you want.
I've seen this exact misconfiguration on three separate client projects. Someone set up Page Rules to enable caching, set an arbitrary TTL in the UI, and then spent months wondering why cache purges from the application didn't work the way they expected.
A Practical Laravel Example
Here's how I set response headers in Laravel for content I actually want Cloudflare to cache:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class ListingsController extends Controller
{
public function index(Request $request): Response
{
$listings = cache()->remember('listings.seattle', 900, function () {
return Listing::published()->orderByDesc('listed_at')->get();
});
$response = response()->view('listings.index', compact('listings'));
// s-maxage controls the CDN (Cloudflare) TTL.
// max-age controls the browser TTL.
// Keep browser cache short so users get fresh data on revisit,
// but let Cloudflare hold it longer and serve it fast.
$response->headers->set(
'Cache-Control',
'public, max-age=60, s-maxage=900'
);
// This tells Cloudflare (and other CDNs) it can cache
// even if the URL has query params - careful with this one.
$response->headers->set('Vary', 'Accept-Encoding');
return $response;
}
}
This does nothing useful without a Cache Rule telling Cloudflare to cache HTML responses. The headers alone won't flip Cloudflare's default behavior. You need both: the right headers and a Cache Rule that marks the URL pattern as cache-eligible.
Once that Cache Rule is in place, Cloudflare reads s-maxage=900 and caches the response for 15 minutes at the edge. The browser gets max-age=60 and caches locally for 1 minute. That split is usually what I want for listing pages.
The Gotchas That Will Bite You
Cookies bypass the cache. If Cloudflare sees a Cookie header on the request, it defaults to bypassing the cache for that request. This is why logged-in users never get cached responses - which is usually correct. But it also means that innocuous cookies (analytics, A/B test flags) can silently destroy your cache hit rate. Check what cookies your site is sending on "anonymous" requests. I've seen Google Analytics _ga cookies cause cache bypass on pages that should have had 90% hit rates.
Query strings matter. By default, Cloudflare treats ?page=1 and ?page=2 as different cache keys, which is correct. But ?utm_source=newsletter is also a different cache key, which means every UTM-tagged URL is a separate cache miss. You can configure Cloudflare to ignore specific query parameters in the cache key. Do this for UTM parameters or your hit rate on marketing campaigns will look terrible.
no-store and private are respected. If you send Cache-Control: private or Cache-Control: no-store, Cloudflare will honor those and bypass its cache. So if you have a middleware somewhere that's adding private to all responses by default (Laravel's default session middleware can do this), nothing will cache regardless of your Page Rules or Cache Rules.
Cloudflare's own edge TTL floors. Even if you send s-maxage=30, Cloudflare has minimum TTLs depending on your plan. On the free plan, the minimum edge TTL for "Cache Everything" is 2 hours for some content types. If you need sub-minute edge cache control, you need a paid plan.
When I Reach for This (and When I Don't)
I use Cloudflare caching aggressively for public-facing pages with shared content: listing pages, product catalogs, blog posts, marketing pages, public API responses. If the same response can be served to 1000 different visitors, it should live at the edge.
I don't use it for anything session-dependent or user-specific. Authenticated dashboards, cart pages, anything with personalization - those should be Cache-Control: private, no-store and bypass the CDN entirely. Getting that wrong means User A could see User B's data, and that's the kind of bug that ends client relationships.
I also don't rely on Cloudflare as my only caching layer. I still cache expensive database queries and external API responses in Redis or the application cache. Cloudflare helps with the last mile. It doesn't fix a slow origin.
The Takeaway
Cloudflare's caching is powerful once you understand that it has its own decision layer sitting above your HTTP headers. Your headers are not ignored - they control TTLs and browser behavior correctly - but whether Cloudflare caches at all is a separate question controlled by Cache Rules or Page Rules.
Check your CF-Cache-Status headers before assuming your caching setup works. I'd bet there are pages on your current projects returning DYNAMIC that you think are being cached.
The mental model shift: think of Cloudflare as a cache that you have to explicitly opt content into, not one that respects HTTP standards by default.
Need help shipping something like this? Get in touch.