When using Cloudfront, how to set the Expires header relative to the current date?

We are developing a large website and all of our images and resources are on Amazon S3. We also use Cloudfront to distribute our content globally. We want the clients web browser to cache our files because when we change them, we will also change the URL (Cloudfront does not reflect the change within 24 hours elsewhere).

We currently use ETags, but this is not optimal, because the Client still has to fulfill 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, as it is possible in the Apache configuration for S3, and we cannot regularly update all the content, because this is largely. Therefore, we need a configuration option that sets the Expires header to Date relative to the current date for all content.

Another solution is to set Cache-Control: max-age to a specific value. It works? Is this accepted by major browsers? Will I be able to destroy some caching algorithms with this? Why does YSlow recommend setting the Expires header, but not Cache-Control: max-age?

Any other recommendations? We compress CSS and JS using Sprites, wherever plausible, setting the Expires and ETags headers where possible, and soon compress our images using the Yahoo compression tool and gzipping Output.

+8
caching amazon-cloudfront cdn pagespeed
source share
2 answers

We did some research. The Cache-Control Header seems to help tell Cloudfront or the proxy to set a valid Expires header, but only sometimes ...

We are currently writing a Cron job to regularly update all headers on S3, because this is one that works for sure. There seems to be no other way. I will keep you posted, if any.

+3
source share

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

you said:

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

What means resources to me never . Why not set the Expires header to the distant, distant dating of the future (e.g. 01/01/2020)?

+2
source share

Source: https://habr.com/ru/post/651353/


All Articles