Question

I've been able to correctly (I think) enable caching on IIS. The only problem now is that when I run Google's PageSpeed Insights it still says

Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network.

But all of the suggestions are external images. I am using Amazon's S3 to externally host images (linking to direct URLs, as

< img src="http://s3.amazon.com......."/>.

Is there a way I can "leverage browser caching" for these external images?

Thanks in advance.

Andy

Était-ce utile?

La solution

Yes, with Amazon S3 you can still set the Expires header of the objects stored in the bucket.

You will have to set this header when storing the object so there are two ways:

  • programatically using the API (set the Expiry header with your PUT request)
  • in the bucket browser that you use to upload the objects

If you use the API you can do something like

PUT /ObjectName HTTP/1.1
Host: BucketName.s3.amazonaws.com
Date: date
Authorization: authorization-string
Expires: expiry-date

http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html

For the second case maybe this link will help: http://www.newvem.com/how-to-add-caching-headers-to-your-objects-using-amazon-s3/

Hope this helps.

Autres conseils

For single images on S3, you can right click on the image in the bucket, go to properties and choose Metadata.

add Key: Cache-Control  and Value: max-age=604800 (this is for 7 days)

This works for me. But if you want to edit them in bulk, I guess you have to try command line. If you do from command line, from my understanding you need to copy the images again to enable the maximum age change to work on the images.

Have you tried:

ExpiresActive On
ExpiresDefault A0    
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
    ExpiresDefault A3024000
    Header append Cache-Control "public"
    </FilesMatch>

in your .htaccess file, hope this helps.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top