Pages Caching

Does cloudflare pages respect Cache-Control headers? If so, how can I validate that? When i use Cache API directly i get a Cache Status HIT response header, however id like to avoid this if possible and would ideally use Cache Rules instead. Ive set it to respect the Cache-Control header and they are set correctly, however cannot see the Cache Status HIT header anymore. Is there another way to validate this working? or does it require the use of the Cache API directly?
10 Replies
Hello, I’m Allie!
By default, Pages uses a custom cache system that doesn’t return Cache Status headers
GATES
GATES4mo ago
Ok, and will it respect the cache headers my UI sets in Cache-Control? i noticed it says it comes out the box with caching defaults but id like to customise these in some cases
Hello, I’m Allie!
No. Pages will cache assets indefinitely, though that is fine because each deployment uses a separate cache/assets are cached on their hash Though Browsers connecting to your Pages Project should respect the Cache-Control headers
GATES
GATES4mo ago
Im happy for the assets to automatically be cached indefinitely, however im thinking mainly about the initial page request and wondering how that could be cached with this
Hello, I’m Allie!
That would be cached too? If that is what you mean
GATES
GATES4mo ago
Like this first request for example. So the assets are fine to indefiniely cache, however depending on page we require to cache differently. Some have authorisation/user logins, some are highly static so can be cached aggressively, and some are user/device specific so we would require to control each page independently, preferably through the Cache-Control headers, so wondering if cloudflare would automatically listen to those for that initial page request, if that makes sense?
Hello, I’m Allie!
Oh, you mean SSR Pages? Those aren’t cached by default Slap the Cache API into whatever you use for SSR, and then cache as you want it to
GATES
GATES4mo ago
Ah yes sorry that’s right 👍 ah ok so we are required to use Cache api in that case? Thanks for the help
Hello, I’m Allie!
Yeah. The great part with that is, if you don't want something to be cached, you don't have to futz with the headers, you just don't call the Cache API at all
GATES
GATES4mo ago
Ok cool I’ll go for that then. Cheers 👌
Want results from more Discord servers?
Add your server