Why does cache.varies not reflect in response headers while cache.maxAge does?
#3529
Unanswered
Leon2xiaowu
asked this question in
Q&A
Replies: 1 comment
-
|
@Leon2xiaowu this is by design.
to also set the // nitro.config.ts
export default defineNitroConfig({
routeRules: {
'/profile': {
cache: { maxAge: 86400, varies: ['cookie', 'accept-language'] },
headers: { 'Vary': 'Cookie, Accept-Language' },
},
},
});or use a middleware if you need more control: // server/middleware/vary.ts
export default defineEventHandler((event) => {
if (event.path.startsWith('/profile')) {
setHeader(event, 'Vary', 'Cookie, Accept-Language');
}
});ref: nitro cache docs |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Nitro team! 👋
I've been exploring Nitro's caching capabilities and noticed an inconsistency in how caching rules are exposed in HTTP responses:
cache.maxAgecorrectly sets theCache-Control: max-age=Xheader (visible in responses). ✅cache.varies(e.g.,varies: ['cookie', 'accept-language']) does not generate aVaryheader in responses. ❌Expected Behavior:
When configuring route rules like:
I expect the response to include:
Current Behavior:
Only
Cache-Controlis present;Varyis missing entirely.Questions:
Vary?Varyheaders alongsidecache.varies?The
Varyheader is critical for correct cache behavior (e.g., when using CDNs or dynamic content). Its absence might lead to improper caching.Thanks for your insights! 🙏
Beta Was this translation helpful? Give feedback.
All reactions