Cloudflare CDN Cache To Support HTTP Vary Header

Currently Cloudflare CDN cache doesn’t seem to support HTTP Vary header as per https://support.cloudflare.com/hc/en-us/articles/115003206852

vary

Cloudflare cache doesn’t respect the vary header

This means if you’re on Cloudflare free plan without access to Polish’s webP support, you can not properly implement webP support on origin server side as Cloudflare CDN cache won’t be able distinguish whether Safari web browsers will serve non-webP images from origin server as Cloudflare CDN cache may have previously cached a webP mime-typed served image to webP supported browser visits from Chrome/Firefox.

End result is on Cloudflare CDN cached .webp origin images get served to web browsers that do not support webP i.e. Safari. Example of the issue is outlined at WebP & Safari Browsers - any suggestions?

Right now I have had to disable Nginx origin webP support if Cloudflare is detected for sites because of this as outlined at https://centminmod.com/webp/.

map $http_accept $webpok {
   default   0;
   "~*webp"  1;
}

map $http_cf_cache_status $iscf {
   default   1;
   ""        0;
}

map $webpok$iscf $webp_extension {
  11          "";
  10          ".webp";
  01          "";
  00          "";
}

So Nginx only enables webP origin support if Cloudflare cache is not detected and browser HTTP request headers support image/webp mime type and disable webP origin support when Cloudflare cache is detected.

This is mainly an issue with Cloudflare free plan as paid plans have Polish webP support.

So suggestion/request is for Cloudflare CDN cache to support HTTP Vary header if possible.

If you use Cloudflare and nginx you should not be forced to pay for webp support.

2 Likes

Hi Eva, thank you very much for reposting this here! I hope there will be a solution for this in the near future. For now, I have found another third party solution. I’m using shortpixel’s CDN for WebP Delivery and resizing now and it seems to work quite nice at the moment. Much cheaper than the cheapest Cloudflare plan. But, of course another plugin to be used which is annoying. Would be much better if Cloudflare and Siteground would figure out a solution for their customers… Cheers Patrick

1 Like

Hope that Cloudflare will add this …

1 Like

I found this discussion when searching for whether CF supported Vary. I was looking at adding this to a current project and fully expected support. I don’t have my notes in front of me, but I think this is also why we can’t use WebP. We’d certainly take advantage of this. Currently I work around it by using custom cache keys.

1 Like