Closed arpadgabor closed 9 months ago
I have exactly the same issue ? did you get it working without a lot of hack in source code directly ? if not I'll try to make a RP
@flapili nope, I patched ipx to fix it in the meantime. Hopefully we can get this fix in the v2 roadmap.
@Atinux and others maintainers does that is a big breaking change in your opinion ?
Hi, dear @flapili, and thanks for explaining your issue.
It is not a breaking change but it is not something I think we could have enabled by default. s-maxage
cache-control directive instructs CDN proxies how long they can keep a resource cached. IPX is not a reverse caching proxy to do so. So if reverse proxy explicitly requests max-age
is zero, it should be respected and checked every time. s-max-age
could be used if for example IPX caches the HTTP response (we might in the future)
For a quick solution, i have added a new option for http.ignoreCacheControl
(can be configured for nuxt image v1 stable) via https://github.com/unjs/ipx/commit/4690342e26612a95b792141241ac2f18effc2cf0 this allows you to opt-out from infering cache-control
header altogether and you can explicitly override maxAge
.
We could also support an option like http.useSMaxAge
but since it is not same semantics for directive, i consider it unsafe to be included but still open to support via another opt-in configuration if you really think would be needed in your case.
Environment
Reproduction
I can pinpoint the location with the bug so it should be enough, please let me know if you need more.
Describe the bug
This code in the http source only accounts for the 1st
max-age
occurence.https://github.com/unjs/ipx/blob/b82adb795e7d376f62d3bbd938b165b34c519085/src/sources/http.ts#L58-L65
Thing is, it seems CloudFront will include both a
max-age
ands-maxage
in the response from a cached object. An excerpt from my object response headers:The regex in the source code ignores the
s-maxage
, as can be noticed in this playground.MDN notes that:
All in all, I think IPX should do either one of two things:
maxAge
was set by the user of the module, ors-maxage
Currently, I am unable to cache
/_ipx/*
images in Nuxt 3 because all images are sent back using themax-age=0
that is inherited from the HTTP source and completely ignores what I had set (I spent way too much time debugging this).Additional context
I might be able to submit a PR for this fix, but let me know what you think would be the best approach (honestly I think a combination of both but prioritize the
maxAge
set by the developer in the IPX options).Logs
No response