Closed SukkaW closed 3 months ago
This is still all very confusing for me, and the docs are sparse regarding best practices for caching.
This is still all very confusing for me, and the docs are sparse regarding best practices for caching.
@surjikal I have already given up this sh***y package. The package shouldn't be used under any circumstances (especially don't use it in your production):
typeof
can be used to determine the Error type.If you still want to use the Cloudflare Workers Page, DO NOT use kv-assets-handler
, implement your own kv handler instead.
hello @SukkaW and @surjikal! I'm working on getting this repo updated this week and beginning to resolve some of the long-standing issues here - I appreciate you both taking the time to write in this ticket. the vast majority of people on our team who maintained this project no longer work at CF, so it's been in a bit of limbo since then, sorry about that!
that being said - although this project has some documentation issues and could use some more clarity, especially around things like caching, it is very much safe to use in production. we've been using it heavily in our marketing and documentation sites in the workers/pages ecosystem. I absolutely understand your frustration, but just want to add some perspective for anyone else who might stumble upon this issue 👍
with that out of the way - let's work on how we can make this better! I'm going to remove this from our upcoming milestone release, which will focus on cloudflare/kv-asset-handler#133 and some other related fixes. if there are people who have been involved in this issue and have since dived deeper into caching work, I'd love to work with you on building better documentation around the things you've mentioned in this issue.
we have a #workers-sites channel in our Discord server that would be a great place to sync up on this stuff too: here's an invite link if anyone would like to come in and chat. thanks!
I’m going to close this issue for now. Going forward, we’ll revisit the assets system as part of Pages/Workers convergence, and will inherit the benefits of the Pages assets system.
In the meantime, Pages is the best choice for deploying sites with static assets. Pages has detailed documentation on it's cache behaviour: https://developers.cloudflare.com/pages/configuration/serving-pages/
I have a few question about
Cache-Control
behavior:1. Will kv-asset-handler respect header set after
getAssetFromKV
?Will the file be cached at Cloudflare Edge for 2 days (default cache behavior) or an hour?
If the answer is an hour (which means the later set
cache-control
is used),Will the file be cached ar Cloudflare Edge for 80 minutes or an hour?
2. How to use
options.cacheControl
as a function?When trying to find the answer of the above question, I went through the code and found this:
https://github.com/cloudflare/kv-asset-handler/blob/eb120a4b789282e4c44ff8b95e2dd2e220b83e6d/src/index.ts#L129-L135
It is never mentioned in the README. Should it be considered not to use in production (Not mentioned in docs thus the behavior might change in the future)?
3. Should
s-max-age
be implemented forcaches.put
insidekv-asset-handler
?https://github.com/cloudflare/kv-asset-handler/blob/eb120a4b789282e4c44ff8b95e2dd2e220b83e6d/src/index.ts#L177-L181
It seems that putting cache into Cloudflare Edge is done by
kv-asset-handler
(Might answer question 1? The headers set later won't be respected?). As far as I know, Cloudflare Edge respect bothmax-age
&s-max-age
, and thes-max-age
takes higher priority (max-age
for browser,s-max-age
for CDN).With
s-max-age
is used, there might be no need for thoseCache-Control
manipulation strategy:https://github.com/cloudflare/kv-asset-handler/blob/eb120a4b789282e4c44ff8b95e2dd2e220b83e6d/src/index.ts#L184-L189
(Is it trying to override
edgeTtl
withbrowserTtl
, and then even deleteCache-Control
if the file shouldn't be cached by browser?)