0

I searched all over and found a method to cache images on Amazon S3. Whenever I upload an image, I add a meta element of cache-control and then set max-age=86400. However, on any sort of speed test site it says that my images do not have a cache applied to them.

I am not sure if it matters, but I have CloudFront linked to this S3 bucket. Sorry, but completely new to AWS.

Anyone know why my images may not be caching?

enter image description here

enter image description hereenter image description here

Paul
  • 3,348
  • 5
  • 32
  • 76
  • Could be the content-type? I see image/jpeg in your settings screenshot, but URLs pasted in below screenshot are .jpg – kosa May 09 '17 at 14:04
  • @Nambari There isn't an option for image/jpg in the meta `content-type`. The only ones listed are within the image I just added to my question. – Paul May 09 '17 at 14:48
  • Just to validate caching is really working or not, may be you can quickly add one of the jpeg (or) png version of your image and test it? If it works, ultimately you might need to change all your JPG images to jpeg (or) png – kosa May 09 '17 at 14:51
  • @Nambari The image `cross-gray` is a png and the `content-type` for this image is `image.png` in S3, but as you can see in my speed test above, the image is displaying as not caching. – Paul May 09 '17 at 14:58

2 Answers2

2

on any sort of speed test site it says that my images do not have a cache applied to them.

That isn't what this says. The screenshot says they have a short freshness lifetime, and longer than 1 week is recommended.

Your setting of max-age=86400 is only 24 hours.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
-1

I recently had this issue (as of 4 Mar 23) after setting my bucket storage cache-control and I used a CDN on my bucket resources. I noticed the bucket items (images) were not displaying any cache-control. In further research I am posting this is anyone stumbles upon this question in searching the same error. I had to go to my CloudFront distributions and select my CDN for the S3 bucket. Select the tab Behaviors, select the default behavior check box and then that will allow you to select EDIT. In the settings scroll down and find Cache key and origin requests and select the check box for Cache policy and origin request policy (recommended) and at the bottom of the form click SAVE. I am not sure if I accepted defaults when I created the CDN bucket or if the default was 'Legacy cache settings' <-- in my case that is what was selected. Once I changed the setting to Cache policy and origin request policy (recommended) my images where now showing the cache-control I had set in my S3 Bucket. I hope this helps anyone else. Happy coding. NOTE: As the accepted answer above mentions the max-age duration <-- I had nothing showing up at all. My max-age was set to 1 year.

Tony B
  • 41
  • 1
  • 8