Reputation: 474
I have a amazon cloudfront distribution that creates a 'origin' to my CDN. In my behavior, I set the Max TTL, Min TTL and default TTL. But my response header does't return the Cache-control header in my static files that are redirected. How to set the cache-control? I need this for the google page insights
Upvotes: 28
Views: 41899
Reputation: 481
Cache-Control
You can add a Cache-Control header to your CloudFront instance without the use of functions. https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-response-headers.html
Upvotes: 26
Reputation: 4011
You can add a Cache-Control header to your CloudFront instance without the use of functions.
Cache-Control
header along with the max age value you want. This value can be set to override origin if you want it.All your responses will now include the cache headers you have set.
Upvotes: 47
Reputation: 405
As mentioned by James, the MAX TTL, MIN TTL, etc that you see in the CF settings when you are creating a distribution, defines the caching behaviour of the CloudFront distribution and the Origin. In other words how long CloudFront should keep the assets in the Edge Locations before checking the origin. For example, if you have an S3 bucket as the origin and then a CloudFront distribution, by setting MAX TTL Min TTL etc you tell CloudFront how often it should check the origin (in this case S3) for changes. You can learn more about it in AWS Docs. Managing How Long Content Stays in an Edge Cache (Expiration).
In the example above you can go to S3 bucket and set the Cache-Control
. For more information how to do it read this one.
Upvotes: 7
Reputation: 4431
You can : 1. configure origin to add the Cache-Control header in response. Or 2. use Lambda@edge (Viewer response as you just want to use it for google page insights) to add Cache-control header in the response. Example: https://github.com/jkrnak/serverless-lambda-at-edge/blob/master/handler.js
Defining TTL doesn't add any cache-control header, it uses to consider how long it need to cache.
Upvotes: 5