Skip to content
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

Support Netlify-Vary header in netlify v2 preset #2431

Closed
Rigo-m opened this issue May 10, 2024 · 6 comments · Fixed by #2440
Closed

Support Netlify-Vary header in netlify v2 preset #2431

Rigo-m opened this issue May 10, 2024 · 6 comments · Fixed by #2440

Comments

@Rigo-m
Copy link
Contributor

Rigo-m commented May 10, 2024

Environment

See reproduction.
Relevant branches:
https://github.com/Rigo-m/netlify-v2-repro/tree/no-cdn-cache-control
https://github.com/Rigo-m/netlify-v2-repro/tree/cdn-cache-control

Check route rules.

Reproduction

https://cache-key-variations.netlify.app/guess?value=2 you can see how this page gets cached at the edge, including the variation on the value query parameter (take a look specifically at the Netlify-Vary heade, the Cdn-Cache-Control header and the Age header for verification).

Here: https://no-cdn-cache-control--netlify-v2-nitro.netlify.app/?page=3 you can see that while the Netlify-Vary header is present, it's not actually caching the page.
Here: https://cdn-cache-control--netlify-v2-nitro.netlify.app/?page=3 you can see that by adding the Cdn-Cache-Control header everything works accordingly.

Describe the bug

Netlify v2 preset appends a Netlify-Cdn-Cache-Control header to instruct the netlify edge platform on how to handle CDN caching.
Only setting this header makes the edge network ignore the Netlify-Vary header (somehow).
We should send the Cdn-Cache-Control header as well, so that when setting the additional header Netlify-Vary from routeRules works accordingly without handling other headers.

Additional context

I'll drop two PRs after #2425 gets merged, one with the relevant fix, another with relevant documentation on the Netlify-Vary header for the netlify v2 preset :)

Logs

No response

@Rigo-m
Copy link
Contributor Author

Rigo-m commented May 10, 2024

@serhalp do you have any insights on the situation?

@serhalp
Copy link
Contributor

serhalp commented May 10, 2024

Hey @Rigo-m, thanks for writing this up.

Isn't a Vary or Netlify-Vary header meaningless when no caching is enabled? I'm not sure I'm understanding why you're expecting the Netlify CDN to cache the serverless function response in this case. The function is even explicitly sending cache-control: no-cache on your repro site.

@Rigo-m
Copy link
Contributor Author

Rigo-m commented May 11, 2024

In the "no-cdn-cache-control" branch you can see that I've set the routeRule for caching the page here, using the new netlify v2 preset.
Now, if you visit the homepage without the query parameter it actually gets cached (check age and cache-control), whilst adding a query parameter returns no-cache.

Setting isr value in routeRules should add the Netlify-Cdn-Cache-Control Header to the response, am I missing anything?

@serhalp
Copy link
Contributor

serhalp commented May 13, 2024

Thanks for clarifying @Rigo-m – I'm with you now.

I think I see where the regression is coming from. I'll have a PR up soon.

@serhalp
Copy link
Contributor

serhalp commented May 13, 2024

@Rigo-m #2440

@Rigo-m
Copy link
Contributor Author

Rigo-m commented May 13, 2024

Amazing, left a small comment for you there

@pi0 pi0 closed this as completed in #2440 May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants