prerender-cloudfront icon indicating copy to clipboard operation
prerender-cloudfront copied to clipboard

CloudFront respects Cache-Control

Open akr4 opened this issue 5 years ago • 4 comments

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 avatar Jan 10 '20 08:01 akr4

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

jinty avatar May 23 '20 14:05 jinty

@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 avatar Oct 30 '21 07:10 berenddeboer

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".

berenddeboer avatar Oct 30 '21 07:10 berenddeboer

@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.

akr4 avatar Oct 31 '21 06:10 akr4