This repository was archived by the owner on Jan 28, 2025. It is now read-only.
feat(aws-cloudfront, s3-static-assets): support setting individual min, max, default CloudFront TTLs, update Cache-Control headers for _next/data files and update all CloudFront behavior TTLs [breaking change for custom CloudFront inputs] #593
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes: #581 and #524
aws-cloudfront
serverless component to allow setting individual default, min and max TTLs._next/data/*
behavior to have min = 0, default = 0 and max = 31536000 for TTLs. Also adds Cache-Control header ofpublic, max-age=0, s-maxage=2678400, must-revalidate
for these.APIs have min = 0, default = 0 and max = 31536000.
_next/static/* have min = 0, default = 86400, and max = 31536000
_static/* have min = 0, default = 86400, and max = 31536000
_next/data/* have min = 0, default = 0, and max = 31536000
default have min = 0, default = 0, and max = 31536000 (same as before)
I think the above makes sense, static files anyway do add cache-control headers, but in case it doesn't we cache 86400 seconds by default. Previously all three TTLs for static files were 86400, so our cache control headers were limited to 86400 even if we set it longer (e.g 31 days or 365 days). And for _next/data/ it was all 0 so they could not be cached. For default, it remains the same. See below for info:
https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html
Note: there is a breaking interface change for CloudFront custom inputs, now it requires users to set individual TTLs instead of just
ttl
. I think this is acceptable since it's now more explicit and I believe not too many users are currently using the custom inputs?Tests
Updated the unit tests. I've also verified the TTLs are set correctly in CloudFront distributions. Caching behavior works as expected for SSR, SSG, and static files, and now also caches _next/data files.
You can validate yourselves here with these various paths:
https://d3q8tfp2sxrn2u.cloudfront.net/anotherSSG/
https://d3q8tfp2sxrn2u.cloudfront.net/anotherSSR/
https://d3q8tfp2sxrn2u.cloudfront.net/_next/data/eFK_r7Za-Hseex4Ydgrvt/anotherSSG.json
https://d3q8tfp2sxrn2u.cloudfront.net/app-store-badge.png
I'll also add these test cases to the e2e tests later.