Caching won't work

Hi all,
I’ve been spending the last two days diving heavily into Cloudflare and have been struggling with getting static resources to cache. No matter what I do, I’ve never seen a CF-Cache-Status header.

I’m using Cloudflare Workers to host a super-simple website (still learning this platform). I’ve tried using Page Rules to turn Origin Cache Control on or off, and I’ve tried every combination of max-age and/or s-maxage headers imaginable but I’ve gotten nowhere.

Here’s some example output using curl:

[email protected] homepage-worker $ curl -I
HTTP/2 200
date: Sun, 20 Feb 2022 07:07:15 GMT
content-type: image/png
content-length: 4525
cache-control: max-age=5, s-maxage=31536000, stale-if-error=86400, no-transform
expect-ct: max-age=604800, report-uri=""
report-to: {"endpoints":[{"url":"https:\/\/\/report\/v3?s=H%2FBvaPRQqHFi%2Fk0IWJrnI5CzjTukSlri07ROSau7UKt%2BpM7mw4oWjMLzGuoKBcX5fBDU%2BGRfJgtpmPBZWuKXV4RWOvCIcif2NEGArsqQcuNBo6%2BNLoRFqBOdkjDKj0cHMC2jwFEQMXA%3D"}],"group":"cf-nel","max_age":604800}
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
server: cloudflare
cf-ray: 6e05e59d4b858c09-EWR
alt-svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400

You can see my worker code here: homepage-worker/worker.mjs at master · mangs/homepage-worker · GitHub

Any ideas would be hugely appreciated. Thanks!

Websites directly served from Workers do not have cf-cache-status header. Caching will not be involved if you serve your websites from Workers - even if you can cache, each incoming request (no matter cached or uncached) will still count as one Workers request.

1 Like

Um, that’s really misleading considering all the documentation related to caching in the Workers documentation. Also, this was written by Cloudflare and it supposedly caches static content in the CDN despite serving out of a worker: @cloudflare/kv-asset-handler - npm

Can you clarify further? If this is all true, I feel like I wasted 2 days worth of time.

Kindly read this, could be related:

1 Like

OMG I FIGURED IT OUT. I found this article in your documentation and this got me the rest of the way there:

I would strongly recommend mentioning that article in early onboarding documentation to save folks from having to go through all the digging I did. Your documentation is good when you can find what you’re looking for, but the contradictory nature of one article vs the next can feel very frustrating at times. Hope this helps save someone else some time. :slight_smile:

1 Like

Thank you for trying to help, I appreciate the quick responses!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.