Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 349
4thSpace Avatar asked Mar 19 '13 14:03

4thSpace


People also ask

Can we use S3 for caching?

S3 is great for file storage, but it does so much more as well. I love using S3 as a simple caching mechanism for any stateless functions that need to save some ephemeral data to keep state.

How do I use browser cache?

The basic idea behind it is the following: The browser requests some content from the web server. If the content is not in the browser cache then it is retrieved directly from the web server. If the content was previously cached, the browser bypasses the server and loads the content directly from its cache.

How do I cache a picture on my Galaxy S3 browser?

For s3 files you would go to properties -> metadata section for each file you want to update. Cloudfront takes headers from the origin. Thanks. Are there any examples of what key/value should be used to control browsing caching?


2 Answers

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

like image 55
Flavio Wuensche Avatar answered Oct 28 '22 18:10

Flavio Wuensche


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
like image 44
Ryu_hayabusa Avatar answered Oct 28 '22 18:10

Ryu_hayabusa