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 withCache-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 needspng
/jpg
or if you can use more advanced format likewebp
(Firefox, Chrome),JPEG 2000
(Safari) andJPEG XR
(IE9+).Now the backend forwards (
301
Moved Permanently
) to eitherdog.png
anddog.jpg
or the converteddog.webm
,dog.jp2
anddog.jxr
as needed.Those static image files are served with appropriate caching headers to be cached by the CDN.