To serve WebP images, I use the rewrite rule in nginx, which checks for file availability and WebP image support. I put it in Apache mod_rewrite since the OP mentioned mod_negotiation. The rewrite looks for a user agent containing the word "chrome" and checks the file with the extension .webp with the same name and path as the .jpg or .png file, and if so, then the WebP file is used. The rewrite rule is a bit cloned, but it does its job.
AddType image/webp .webp
For my site, I have the option to upload my photos via JavaScript after I can detect WebP support in the browser instead of relying on a user agent string. If there is WebP support, than I set a cookie before starting to download the images. Therefore instead RewriteCond
RewriteCond %{HTTP_USER_AGENT} (chrome) [NC]
I would use this
RewriteCond %{HTTP_COOKIE} supports_webp
christiangeek
source share