Search code examples
htmlcachingiis-7.5pagespeed

Leverage browser caching - external images


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


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.