#Cache HTML pages

85 messages · Page 1 of 1 (latest)

small lagoon
#

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:

#

I'm trying to NOT set up a manual cache rule, but still serve that page from the CDN

wind kraken
#

You need a Page rule with Cache Everything or a Cache Rule with Cache Enabled to get it to cache html

small lagoon
#

so we do need a cache rule for each url we want cached?

#

I can't do it via headers only?

wind kraken
#

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

small lagoon
#

ya 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

wind kraken
small lagoon
#

oh blah forgot to turn that on HAHAHAHAHA

#

sigh

#

sheesh

#

(had to turn it off to get SSL set up)

wind kraken
#

yea turn on proxy and give it a bit for dns cache/propagation

wind kraken
# small lagoon I have a rule

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

small lagoon
#

still nothing, shoot

wind kraken
#

check the response headers for server: cloudflare and cf-cache-status

#

dns cache can take a while

small lagoon
#

ya I don't see those

wind kraken
#

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

small lagoon
#

nah we use cf

wind kraken
#

at min though it'd take 5 minutes (you had 300s ttl before)

small lagoon
#

ok perfect, I have to run now, thanks for your help, much appreciated

small lagoon
#

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?

#

@wind kraken

small lagoon
wind kraken
#

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.
wind kraken
small lagoon
#

a specific edge cache ttl?

small lagoon
#

sorry for the questions but the docs are very technical and they're hard to figure out sometimes

wind kraken
#

like so:

small lagoon
#

thanks a lot, we don't like the Rule idea but we don't need the cookies on these pages, and that works great

small lagoon
#

@wind kraken 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

wind kraken
# small lagoon <@905865275583365161> I'm still struggling with this, are you able to help? it s...

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.
small lagoon
#

ok, so how can I get this page cached?

wind kraken
#

Stop serving set-cookie headers, or override the edge ttl

small lagoon
#

ok perfect, that's what I thought, wanted to confirm

#

the docs are very confusing about what steps you need to take

wind kraken
#

are they? I think that bit about the set-cookie part I quoted explains it pretty simply

small lagoon
#

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?

wind kraken
#

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

small lagoon
#

I thought Page rules were deprecated?

wind kraken
#

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

small lagoon
#

what do "origin cache control" do? what are the consequences of disabling?

wind kraken
wind kraken
small lagoon
#

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

wind kraken
#

Any plan can disable OCC in Page Rules

#

Only ENT can disable OCC In Cache Rules

small lagoon
#

that seems....weird

wind kraken
small lagoon
#

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

wind kraken
small lagoon
#

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

wind kraken
#

setting up a dummy origin/website can be helpful too

#

find out by experimenting ;p

small lagoon
#

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