Support Vary:Accept header (for conditional webp)


The purpose of the Vary header is to inform shared caches, such as CDNs and proxies, that the response varies, and the cache should therefore not only be keyed by URL, but also by the value(s) in the header.

As the webp format is gaining momentum, there is an increase in solutions where (origin) servers returns webp for browsers that supports it and jpeg / png for browsers that doesn’t. To signal the varied response, these solutions add a Vary:Accept header. The solution has been around for a while, and KeyCDN has also written about it in your blog:

There are multiple ways you can implement this.

  • You can always forward Accept headers to origin servers, or only when configured to
  • You can always use the Accept header as key, when the origin server returns a Vary:Accept header, or only when configured to
  • You can narrow it down so instead of using the whole Accept header as key, you can transform it into a boolean, which is TRUE when the Accept header contains “image/webp” in the string, and FALSE otherwise. This will limit the number of variation to just two - and thus limiting the disk space needed AND increase the chance for a HIT. Currently there are not too many variations of Accept headers around (, but this might change


FYI, we’ve talked about this quite a bit here: Content negociation for WebP / JXR


Oh - hi Shane!

Yes, I see - thanks. And I see that you made the same proposal about not using the whole Accept header as key :slight_smile: - and for the same reason.