1

I've read through the documentation and attempted to setup permanent cloudfront caching. The idea is that once you download an image you shouldn't need to download it again. I'm looking at my network tab and I don't think it is. Can someone tell me if this file has the correct cache settings?

https://d2t4fc8ff77neh.cloudfront.net/cardSrcMedia/1abqkohet_plain_red_heart_graphic_with_a_drop_shadow_0071-0910-0216-0922_SMU.jpg

My headers:

var headers = {
  'Content-Length': options.data.length,
  'Vary': 'Accept-Encoding',
  'Expires': 1000 * 60 * 60 * 24 * 365 * 5,
  'x-amz-acl': 'public-read',
  'Content-Type': options.type
}
Harry
  • 52,711
  • 71
  • 177
  • 261

1 Answers1

2

It looks like your image is being cached by CloudFront, but your expires header value isn't valid.

From the HTTP 1.1 spec (https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html):

The format is an absolute date and time as defined by HTTP-date in section 3.3.1; it MUST be in RFC 1123 date format

and

HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired").

and

To mark a response as "never expires," an origin server sends an
Expires date approximately one year from the time the response is
sent. HTTP/1.1 servers SHOULD NOT send Expires dates more than one
year in the future.

It's probably better to use a Cache-control header as this supersedes the Expires header. Something like this should produce the same effect:

Cache-Control: max-age=31536000
Mark Kelly
  • 553
  • 4
  • 13
  • 1
    The [CloudFront docs](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Expiration.html) also support the position of using `Cache-Control` instead of `Expires`. Also, the question really seems to be more about browser caching, but note that CloudFront does not guarantee that it will cache the objects for the time specified, only that it won't cache them *longer*... covered [here](http://stackoverflow.com/a/26638663/1695906) and [here](http://stackoverflow.com/a/32878535/1695906). – Michael - sqlbot Feb 18 '16 at 23:44