Question

We are developing a big Website, and all our Images and Resources are in Amazon S3. We are also using Cloudfront to globally distribute our Content. What we want to to, is to tell the Clients Web Browser to cache our Files, because when we change them, we also will change the URL (Cloudfront does not reflect the change for 24 Hours elsewhere).

We are currently using ETags but this is not optimal becaue the Client still has to do the Request to check if the Resource has changed.

One Solution would be the Expires Header, but we did not find a way to set it relative to the current Date like possible in the Apache Configuration for S3, and we cannot update all Content regularly, because it is pretty much. So we would need a Configuration Option that sets the Expires Header to a Date relative to the current Date for all Content.

Another Solution would be to set Cache-Control: max-age to a certain Value. Does this work? Is it accepted by major Browsers? Will I destroy some caching Algorithms with this? Why does YSlow recommend to set the Expires header but not Cache-Control: max-age?

Any other Recommendations? We are compressing CSS and JS, using Sprites where it is plausible, setting Expires headers and ETags where it is possible, and will soon compress our Images with the Yahoo Compression Tool and gzipping Output.

Was it helpful?

Solution

We did some research on ourself. Seems like the Cache-Control Header does help with telling Cloudfront or a Proxy to set a valid Expires header, but only sometimes ...

We are currently writing a Cron Job to update all Headers in the S3 regularly, because that is one thing that works for sure. Seems like there is no other way. I will keep you posted if there is.

OTHER TIPS

Why do you need the cache duration to be relative to the current date ?

you said :

"when we change them, we also will change the URL"

Which to me means your resources never change. Why not then set an Expires Header to a far far far future date (01/01/2020 for example) ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top