Cache HTML pages
I'm trying to get CF to cache my home page, what headers do I need to make that happen? Current this is what is set:
51 Replies
I'm trying to NOT set up a manual cache rule, but still serve that page from the CDN
You need a Page rule with Cache Everything or a Cache Rule with Cache Enabled to get it to cache html
otherwise it's just these extensions: https://developers.cloudflare.com/cache/concepts/default-cache-behavior/
Cloudflare Docs
Default Cache Behavior · Cloudflare Cache (CDN) docs
Cloudflare respects the origin web server’s cache headers in the following order unless an Edge Cache TTL cache rule overrides the headers. Refer to …
so we do need a cache rule for each url we want cached?
I can't do it via headers only?
you can do it for the entire hostname
but yea, you need a cache or page rule
cache rules are super flexible though. You can do it for the entire hostname (using hostname eq example.com, etc), for everything on your domain, for just things without extensions (path ends with
/
), etcya trying to trigger it caching and I still can't not quite sure what I'm missing
I have a rule
and the headers above
but still nothing is cached
so, I'm missing something
that hostname isn't proxied/going through CF's CDN
oh blah forgot to turn that on HAHAHAHAHA
sigh
sheesh
(had to turn it off to get SSL set up)
yea turn on proxy and give it a bit for dns cache/propagation
you can just do
Hostname
equals
static-test.zaytuna.edu
to make all assets on the subdomain eligible/that cache rule to apply to allstill nothing, shoot
check the response headers for server: cloudflare and cf-cache-status
dns cache can take a while
ya I don't see those
https://headers.live/?url=https://static-test.zaytuna.edu
if you are using your default dns resolver, it's probably provided by your ISP, and some ISPs override ttl to hours to reduce cache
nah we use cf
at min though it'd take 5 minutes (you had 300s ttl before)
ok perfect, I have to run now, thanks for your help, much appreciated
ok, so now why is it a redirect?
and what does this mean?
is there a header that indicates if it's served from the cache?
ah it's this
Cloudflare also sets BYPASS when your origin web server sends cookies in the response header.
so you can't cache a page that has cookies?
@Chaikathere's a doc for the cookie behavior here: https://developers.cloudflare.com/cache/concepts/cache-behavior/#interaction-of-set-cookie-response-header-with-cache
Cloudflare Docs
Head Requests and Set-Cookie Headers · Cloudflare Cache (CDN) docs
In this page, we document how Cloudflare’s cache system behaves in interaction with:
still not quite sure what I need to do?
Interaction of Set-Cookie response header with Cache For non-cacheable requests, Set-Cookie is always preserved. For cacheable requests, there are three possible behaviors: Set-Cookie is returned from origin and the default cache level is used. If origin cache control is not enabled, Cloudflare removes the Set-Cookie and caches the asset. If origin cache control is enabled, Cloudflare does not cache the asset and preserves the Set-Cookie. A cache status of BYPASS is returned. Set-Cookie is returned from origin and the cache level is set to Cache Everything. In this case, Cloudflare preserves the Set-Cookie but does not cache the asset. A cache MISS will be returned every time. Set-Cookie is returned from origin, the cache level is set to Cache Everything and edge cache TTL is set. In this case, Cloudflare removes the Set-Cookie and the asset is cached.do you want it to be cached and to ignore the cookie? Either stop serving the cookie or set a specific edge cache ttl
a specific edge cache ttl?
do you mean one of these? https://developers.cloudflare.com/cache/how-to/edge-browser-cache-ttl/create-page-rules/#cache-everything
sorry for the questions but the docs are very technical and they're hard to figure out sometimes
You're good, you can override it in your Cache Rule
like so:
thanks a lot, we don't like the Rule idea but we don't need the cookies on these pages, and that works great
@Chaika I'm still struggling with this, are you able to help? it seems to only work when I set the Edge TTL manually and ignore the cache control header
I'd like this page to be cached: https://headers.live/?url=https://edge.transformstudios.com/test
View HTTP headers of any website
View the HTTP Headers of any website, live. Perform a GET request and read all HTTP headers.
yea, that's the documented behavior:
https://developers.cloudflare.com/cache/concepts/cache-behavior/#interaction-of-set-cookie-response-header-with-cache
Set-Cookie is returned from origin and the default cache level is used. If origin cache control is not enabled, Cloudflare removes the Set-Cookie and caches the asset. If origin cache control is enabled, Cloudflare does not cache the asset and preserves the Set-Cookie. A cache status of BYPASS is returned. Set-Cookie is returned from origin and the cache level is set to Cache Everything. In this case, Cloudflare preserves the Set-Cookie but does not cache the asset. A cache MISS will be returned every time. Set-Cookie is returned from origin, the cache level is set to Cache Everything and edge cache TTL is set. In this case, Cloudflare removes the Set-Cookie and the asset is cached.
ok, so how can I get this page cached?
Stop serving set-cookie headers, or override the edge ttl
ok perfect, that's what I thought, wanted to confirm
the docs are very confusing about what steps you need to take
are they? I think that bit about the set-cookie part I quoted explains it pretty simply
well there's this part
If origin cache control is not enabled, Cloudflare removes the Set-Cookie and caches the asset.
what does that mean? Can I turn off the origin cache control
part?occ is enabled by default
If you wanted to keep your origin's cache-control age and force caching without removing the set-cookie header, you could try disabling occ with a page rule
I thought Page rules were deprecated?
They're legacy yea
You can't disable OCC in Cache Rules without Enterprise right now, which is a silly restriction and something I raised to them, but nothing yet
what do "origin cache control" do? what are the consequences of disabling?
Cloudflare Docs
Origin Cache Control · Cloudflare Cache (CDN) docs
Origin Cache Control is a Cloudflare feature. When enabled on an Enterprise customer’s website, it indicates that Cloudflare should strictly respect …
basically occ disabled is "stop listening to the headers, and only listen to overrides"
ok so we likely want to keep it on and the best solution is to remove those set-cookie headers
not to mention we can't disable right now, with the level we're on
for sure
maybe I was unclear, but that's why I said use Page Rules
Any plan can disable OCC in Page Rules
Only ENT can disable OCC In Cache Rules
that seems....weird
ok, thanks again, sorry for my confusion, there's so much information in the docs and they have much assumed knowledge.
appreciate your patience with me
Sure, no worries, sometimes you just have to know what you're looking for
I read all those things many times yesterday
still didn't get it
anyway, I'm good now
back to seeing how I can remove those headers
setting up a dummy origin/website can be helpful too
find out by experimenting ;p
that's what I have
but I can't figure out how to remove those headers anymore...it worked at one point but I upgraded Laravel and now it doesn't. Digging in to that now
that
edge.transformstudios.com
is a test site/domain
Thanks so so much for your help @Chaika, I got it all working