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 ?
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.
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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With