4thSpace
4thSpace

Reputation: 44352

How to use browser caching with Amazon S3?

I get the following on gtmetrix.com:

Leverage browser caching    
E (55)
52%
Server  High
What does this mean?
The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

http://mysite.s3.amazonaws.com/profile.png (expiration not specified)
http://mysite.s3.amazonaws.com/circle.player.css (expiration not specified)
http://mysite.s3.amazonaws.com/main.js (expiration not specified)
http://mysite.s3.amazonaws.com/not.the.skin.css (expiration not specified)
http://cdn-images.mailchimp.com/embedcode/slim-321711.css (expiration not specified)

I'm guessing the mailchimp files can't be modified. But how do I specify a browser cache for Amazon S3 Cloudfront files?

Upvotes: 19

Views: 23623

Answers (3)

Flavio Wuensche
Flavio Wuensche

Reputation: 10386

Via Amazon Management Console, select your file (or folder).

enter image description here


Go to the Properties tab and click on Metadata.

enter image description here


Finally, add Cache-Control to its header and save.

enter image description here

Upvotes: 29

Ryu_hayabusa
Ryu_hayabusa

Reputation: 3722

You can specify header parameter with the s3cmd! while uploading files to s3.

eg :

s3cmd sync LOCAL_DIRECTORY s3://BUCKET[/PREFIX] --add-header=Cache-Control:max-age=3153600

Upvotes: 12

datasage
datasage

Reputation: 19573

When you store files to s3. You can set custom headers which will be send to the client. In this case, you can set an Expires header for your files.

Cloudfront works a little bit differently as it depends on your origin.

Upvotes: 8

Related Questions