Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

Conversation

dphang
Copy link
Collaborator

@dphang dphang commented Sep 8, 2020

This fixes: #581 and #524

  • Update aws-cloudfront serverless component to allow setting individual default, min and max TTLs.
  • Update CloudFront _next/data/* behavior to have min = 0, default = 0 and max = 31536000 for TTLs. Also adds Cache-Control header of public, max-age=0, s-maxage=2678400, must-revalidate for these.
  • Update other CloudFront behaviors with the following TTLs:

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.

…n, max, default CloudFront TTLs, update Cache-Control headers and TTLs for _next/data files
@dphang dphang changed the title feat(aws-cloudfront, s3-static-assets): support setting individual min, max, default CloudFront TTLs, update Cache-Control headers for _next/data files and fix CloudFront TTLs 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 Sep 8, 2020
@dphang dphang changed the title 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 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] Sep 8, 2020
@dphang dphang changed the title 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] 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]] Sep 8, 2020
@dphang dphang changed the title 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]] 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] Sep 8, 2020
Copy link
Contributor

@danielcondemarin danielcondemarin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@danielcondemarin danielcondemarin merged commit fb8e61d into serverless-nextjs:master Sep 8, 2020
@danielcondemarin
Copy link
Contributor

Don't worry about the breaking change to the aws-cloudfront library. Is not really meant to be consumed outside of the serverless-next.js component.

@dphang dphang deleted the fix-json-data-files branch September 8, 2020 22:04
@dphang dphang mentioned this pull request Sep 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON data files not properly cached

2 participants