Closed zakdma closed 2 months ago
I hope this will help someone like me, that are struggling with Cache-Control header has not been populated. You can see there is a TRANSFORMED_IMAGE_CACHE_TTL constant that should be used for cache control for images. It defined here https://github.com/aws-samples/image-optimization/blob/main/functions/image-processing/index.mjs#L10 It then used to put cache-control for image saved to S3 https://github.com/aws-samples/image-optimization/blob/main/functions/image-processing/index.mjs#L93 This will only add x-amz-meta-cache-control header but not Cache-Control header. And Google Page Speed will tell you that images are not cached at all. According to documentation, there is not metadata but a separate field CacheControl when you put the object to S3 https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html So you have to add it to be populated in the response. Just add this line CacheControl: TRANSFORMED_IMAGE_CACHE_TTL, above the
Cache-Control
TRANSFORMED_IMAGE_CACHE_TTL
x-amz-meta-cache-control
CacheControl: TRANSFORMED_IMAGE_CACHE_TTL,
Metadata: { 'cache-control': TRANSFORMED_IMAGE_CACHE_TTL, },
Thank you very much for this valuable correction. It's a miss on our side. I just made the change https://github.com/aws-samples/image-optimization/commit/fb06adbec7c26208917c52a40c8b2aa61e35ad61
I hope this will help someone like me, that are struggling with
Cache-Control
header has not been populated. You can see there is aTRANSFORMED_IMAGE_CACHE_TTL
constant that should be used for cache control for images. It defined here https://github.com/aws-samples/image-optimization/blob/main/functions/image-processing/index.mjs#L10 It then used to put cache-control for image saved to S3 https://github.com/aws-samples/image-optimization/blob/main/functions/image-processing/index.mjs#L93 This will only addx-amz-meta-cache-control
header but notCache-Control
header. And Google Page Speed will tell you that images are not cached at all. According to documentation, there is not metadata but a separate field CacheControl when you put the object to S3 https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObject.html So you have to add it to be populated in the response. Just add this lineCacheControl: TRANSFORMED_IMAGE_CACHE_TTL,
above the