-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐞] CacheControl s-maxage and stale-while-revalidate not applied on vercel edge #5192
Comments
Thanks for the detailed analysis. Yes, PR would be most welcome. I am not an expert in the nuances of different edge providers, so I am unsure about the best way to do this. We could add this to vercel adopter only? |
I have already started working on this. I have come up with a fourth alternative : cacheControl: (
options: CacheControl['options'],
target: CacheControl['target'] = 'Cache-Control'
) => {
check();
headers.set(target, createCacheControl(options));
}, This will allow using cacheControl just like before for backwards compatibility cacheControl({
maxAge: 300,
sMaxAge: 600,
}); Or with the optional parameter cacheControl({
maxAge: 300,
sMaxAge: 600,
}, "CDN-Cache-Control"); This way, it works for any target imaginable. |
Sweet! Looking forward to a PR. |
Add second `target` argument to cacheControl for backwards compatibility. Fix QwikDev#5192
Add second `target` argument to cacheControl for backwards compatibility. Fix #5192
Which component is affected?
Qwik City (routing)
Describe the bug
Using
cacheControl
in aRequestHandler
, vercel edge doesn't apply staleWhileRevalidate and sMaxAge properties.On their docs:
For example, with code from the basic template:
Vercel edge will only apply
max-age: 5
to the header.Screenshot:
Deployed demo: https://qwik-vercel-edge-cache-trim-issue.vercel.app/demo/todolist/
My current way to solve this issue is to use
event.headers.set
twice with Cache-Control and CDN-Cache-Control:Potential solutions
I'd love to make a PR for this, but I'm not sure what would be the best approach to solve this since we can already work around this issue with
headers.set
.Here are my propositions:
1)
Add
headers.set
documentation to https://qwik.builder.io/docs/caching/2)
Add
headers.set('CDN-Cache-Control', createCacheControl(cacheControl));
in
which would give
in packages/qwik-city/middleware/request-handler/request-event.ts
3)
Add a new eventHandler prop:
in packages/qwik-city/middleware/request-handler/request-event.ts
Either way, I think 1 would be beneficial. 2 would make an easier-to-use API and could end up in a better DX. It may be what the developer will be looking for most of the time and will work with most deployment solutions. 3 would give a bit more control. I think it would be good to do 1 and 2, because I think developers will expect
cacheControl
to work properly out of the box with vercel edge.But the problem with 2 and 3 is that they would not account for other
Cache-Control
variations likeVercel-CDN-Cache-Control
and any other variation that exists or will exist (I don't know all of them). What do you think about supporting other variations @mhevery?Reproduction
https://github.com/maiieul/qwik-vercel-edge-cache-trim-issue
Steps to reproduce
System Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: