Setting Cache with Amazon S3

As part of my other post about Alexander Headland surf I had to get the images from the camera to the laptop to the server to you.

Most of those steps are pretty straight forward, but the path from the laptop to the server can be done better than you might think.

I use Amazon S3 for some storage hosting, I put some backups up there, I used to synchronise all of my images up to S3 and I even serve all of the assets from my wordpress surferm.ag site from Amazon S3.

The uploading part is really simple with S3 which is one of the reasons it’s really popular, also it’s a lot cheaper to pay for diskspace and data transfer with them over someone like Media Temple.

For a long time though I was blindly uploading my images/css/js without thinking about cache. Just because the assets were being served from a content distribution network (CDN) didn’t mean that you yourself couldn’t benefit form a little cache.

When you’re uploading your files to Amazon S3 be sure to set Metadata against the files AS YOU UPLOAD. Once they’re up there they can not be changed, so do this during the upload.

Set the met data Cache-Control to the value of max-age=864000. This gives you 10 days worth of cache on the images you upload (increase it if you need).

Easy huh.

Leave a comment

Your email address will not be published. Required fields are marked *