Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expires Header max value

I have several millions of image files on a S3 storage bucket and I know they will never change. To optimize requests, I decided to add an expires header to my files (as explained here : google page speed rules)

The process of adding the headers to all my files is long and expensive so I'd prefer not to repeat it. However, the Http Rfc recommends to set Expires header with a max expiration date of one year in the future :

HTTP/1.1 servers SHOULD NOT send Expires dates more than one year in the future

...which means I would have to update my headers in one year.

My question is :

Can I set my headers values to a very far date (e.g: 01-01-2020) and go against the RFC recommendation ? What is the risk of doing so ?

Is there another solution to tell the clients that request my files to cache them for an infinite duration, without having to update anything on my amazon S3 storage ?

like image 239
Benjamin Simon Avatar asked May 04 '11 15:05

Benjamin Simon


People also ask

What is an expire header?

The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.

Should I add expired headers?

Expires headers can help you control how different file types are cached and served to your visitors. They can not only help improve load times for returning visitors but also ensure they're only seeing fresh content. That's why they're important to website speed and the overall user experience.

What is Max-age in cache-control?

Cache-control: max-age It is the maximum amount of time specified in the number of seconds. For example, max-age=90 means that a HTTP response remains in the browser as a cached copy for the next 90 seconds before it can be available for reuse.


2 Answers

You could also set the more modern header:

Cache-Control: max-age=31536000, public

Each user agent will, upon loading each image, be willing to keep it cached for an entire year before asking for a new copy. (The large integer there is 365 × 24 × 60 × 60 seconds.) If there are still browsers out there that do not understand Cache-Control, they might gradually disappear over the lifespan of your images!

like image 122
Brandon Rhodes Avatar answered Oct 12 '22 22:10

Brandon Rhodes


You can set your header values to a maximum of around 19 january 2038 (max 32bit timestamp). This is what Google did, for some time, on their tracking cookies expiry time.

The only risk of doing so is that if one day, for some reason, you decide to change an image (or notice there is a problem with one or more), your clients will not download the new version. You decide if it's worth taking the risk.

Other than that, I don't really see any potential problem.

like image 27
user703016 Avatar answered Oct 12 '22 23:10

user703016