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:
No description
51 Replies
Erin
ErinOP7mo ago
I'm trying to NOT set up a manual cache rule, but still serve that page from the CDN
Chaika
Chaika7mo ago
You need a Page rule with Cache Everything or a Cache Rule with Cache Enabled to get it to cache html
Chaika
Chaika7mo ago
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 …
Erin
ErinOP7mo ago
so we do need a cache rule for each url we want cached? I can't do it via headers only?
Chaika
Chaika7mo ago
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 /), etc
Erin
ErinOP7mo ago
ya trying to trigger it caching and I still can't not quite sure what I'm missing
Erin
ErinOP7mo ago
I have a rule
No description
Erin
ErinOP7mo ago
and the headers above but still nothing is cached so, I'm missing something
Chaika
Chaika7mo ago
that hostname isn't proxied/going through CF's CDN
Erin
ErinOP7mo ago
oh blah forgot to turn that on HAHAHAHAHA sigh sheesh (had to turn it off to get SSL set up)
Chaika
Chaika7mo ago
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 all
Erin
ErinOP7mo ago
still nothing, shoot
Erin
ErinOP7mo ago
No description
Chaika
Chaika7mo ago
check the response headers for server: cloudflare and cf-cache-status dns cache can take a while
Chaika
Chaika7mo ago
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
Erin
ErinOP7mo ago
nah we use cf
Chaika
Chaika7mo ago
at min though it'd take 5 minutes (you had 300s ttl before)
Erin
ErinOP7mo ago
ok perfect, I have to run now, thanks for your help, much appreciated
Erin
ErinOP7mo ago
ok, so now why is it a redirect?
No description
Erin
ErinOP7mo ago
and what does this mean?
No description
Erin
ErinOP7mo ago
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? @Chaika
Chaika
Chaika7mo ago
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:
Erin
ErinOP7mo ago
still not quite sure what I need to do?
Chaika
Chaika7mo ago
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
Erin
ErinOP7mo ago
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
Chaika
Chaika7mo ago
You're good, you can override it in your Cache Rule
Chaika
Chaika7mo ago
like so:
No description
Erin
ErinOP5mo ago
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
Erin
ErinOP5mo ago
View HTTP headers of any website
View the HTTP Headers of any website, live. Perform a GET request and read all HTTP headers.
Chaika
Chaika5mo ago
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.
Erin
ErinOP5mo ago
ok, so how can I get this page cached?
Chaika
Chaika5mo ago
Stop serving set-cookie headers, or override the edge ttl
Erin
ErinOP5mo ago
ok perfect, that's what I thought, wanted to confirm the docs are very confusing about what steps you need to take
Chaika
Chaika5mo ago
are they? I think that bit about the set-cookie part I quoted explains it pretty simply
Erin
ErinOP5mo ago
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?
Chaika
Chaika5mo ago
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
Erin
ErinOP5mo ago
I thought Page rules were deprecated?
Chaika
Chaika5mo ago
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
Erin
ErinOP5mo ago
what do "origin cache control" do? what are the consequences of disabling?
Chaika
Chaika5mo ago
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 …
Chaika
Chaika5mo ago
basically occ disabled is "stop listening to the headers, and only listen to overrides"
Erin
ErinOP5mo ago
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
Chaika
Chaika5mo ago
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
Erin
ErinOP5mo ago
that seems....weird
Erin
ErinOP5mo ago
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
Chaika
Chaika5mo ago
Sure, no worries, sometimes you just have to know what you're looking for
Erin
ErinOP5mo ago
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
Chaika
Chaika5mo ago
setting up a dummy origin/website can be helpful too find out by experimenting ;p
Erin
ErinOP5mo ago
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
Want results from more Discord servers?
Add your server