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

CloudFront respects Cache-Control #16

Open
akr4 opened this issue Jan 10, 2020 · 4 comments
Open

CloudFront respects Cache-Control #16

akr4 opened this issue Jan 10, 2020 · 4 comments

Comments

@akr4
Copy link

akr4 commented Jan 10, 2020

Hello. This repo is very helpful. Thank you.
I just want to tell about X-Prerender-Cachebuster. CloudFront respects Cache-Control header from Lambda@Edge functions. I set Cache-Control: no-cache, no-store in my origin-response function and works fine for me.
https://aws.amazon.com/premiumsupport/knowledge-center/prevent-cloudfront-from-caching-files
Hope this helps.

@akr4 akr4 changed the title CloudFront respects Cache-Control from custom origins CloudFront respects Cache-Control Jan 10, 2020
@jinty
Copy link
Owner

jinty commented May 23, 2020

Interesting. Using cache control rather than a random token would definite be better. Would you be able to work up a pull request?

@berenddeboer
Copy link

@akr4 how exactly does this work? Prerender needs to visit the site without CloudFront doing any caching. I can't see how Cache-Control would help here, that's nice when returning data from your origin, but after you rewrite the origin, prerender will visit the site as if it was a browser: how would you avoid caching then? I.e. you want to avoid caching for incoming requests.

@berenddeboer
Copy link

Ah, I think I understand how this could work: on viewer-request check if the user-agent is "Prerender". In that case you should make sure a cached version is never returned. Not sure yet how.

Then on origin-response you set "Cache-Control".

@akr4
Copy link
Author

akr4 commented Oct 31, 2021

@berenddeboer Returning the Cache-Control header from origin-response prevents CloudFront from caching the response. In addition to that, you need to set a header in viewer-request to distinguish the request is from prerender.io. And add it to a cache key of your CloudFront settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants