Impossible to serve WebP images using CloudFlare? Impossible to serve WebP images using CloudFlare? nginx nginx

Impossible to serve WebP images using CloudFlare?


With the example of having dog.png and dog.jpg.

  • Have your backend serve a /dog (without any file extension) which will always respond with Cache-Control: private and thus be never cached by the CDN.

  • Your backend will now always get hit for that url, and can analyze the headers like the Accept header, and decide if the browser needs png/jpg or if you can use more advanced format like webp (Firefox, Chrome), JPEG 2000 (Safari) and JPEG XR (IE9+).

  • Now the backend forwards (301 Moved Permanently) to either dog.png and dog.jpg or the converted dog.webm, dog.jp2 and dog.jxr as needed.

  • Those static image files are served with appropriate caching headers to be cached by the CDN.