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
Files to create cache-control
My header responses
If you want to enable Cache-Control for all files, add Header set line outside the filesMatch block. As you can see, we set the Cache-Control header's max-age to 3600 seconds and to public for the listed files.
Open the CloudFront console at https://console.aws.amazon.com/cloudfront/v3/home . Choose Create distribution. In the Cache key and origin requests section, make sure that Cache policy and origin request policy is chosen. For Cache policy, choose the cache policy to attach to this distribution's default cache behavior.
Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).
private. The private response directive indicates that the response can be stored only in a private cache (e.g. local caches in browsers). You should add the private directive for user-personalized content, especially for responses received after login and for sessions managed via cookies.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With