friism
friism

Reputation: 19279

AWS CloudFront, `Vary` header and content negotiation

I'm trying to implement content negotiation based on client Accept headers so that clients that accept image/webp get webp images while clients that don't get plain old jpeg. webp and jpeg image are served from the same url, i.e. /images/foo-image/ and the content returned varies on the Accept header presented by the client. This now works great on my site.

Next challenge is to get this working AWS CloudFront sitting in front of my site. I'm setting the Vary header to Vary: Accept to let CloudFront know that it has to cache and serve different content based on the client Accept headers.

This doesn't seem to work unfortunately, i.e. CloudFront just serves up whatever it first gets it's hands on, Vary and Accept notwithstanding. Interestingly, CloudFront does seem to be able to vary content based on Accept-Encoding (i.e. gzip).

Does anyone know what gives?

Upvotes: 5

Views: 7445

Answers (2)

friism
friism

Reputation: 19279

It turns out this is documented as not supposed to work:

The only acceptable value for the Vary header is Accept-Encoding. CloudFront ignores other values.

UPDATE: AWS now has support for more sophisticated content negotiation. I wrote a blog post on how to take advantage of this.

Upvotes: 6

Andrew Bullock
Andrew Bullock

Reputation: 37398

Just to update this question, CloudFront now supports caching by different headers, so you can now do this

Upvotes: 2

Related Questions