3 ms·
It's easier to do this on the server side based on Accept header, e.g. for Apache to serve image.jpg.webp instead of image.jpg: RewriteCond %{HTTP_ACCEPT} im
by dchest 5y ago
It's easier to do this on the server side based on Accept header, e.g. for Apache to serve image.jpg.webp instead of image.jpg:
RewriteCond %{HTTP_ACCEPT} image/webp
RewriteCond %{REQUEST_FILENAME}.webp -f
RewriteRule ^/?(.+?)\.(jpe?g|png)$ /$1.$2.webp [NC,T=image/webp,E=EXISTING:1,E=ADDVARY:1,L]
<FilesMatch "(?i)\.(jpe?g|png)$">
Header append "Vary" "Accept"
</FilesMatch>
Then <img src="image.jpg"> will serve the supported format.
- bmn__ 5y agoThat's a poor quality conneg implementation, don't recommend. Apache httpd comes with mod_negotiation, use that instead to be standard compliant. <https://httpd.apache.org/docs/current/content-negotiation.html https://httpd.apache.org/docs/current/content-negotiation.ht...> <img src="image"> without extension on the URI will pick the user-agent's best accepted format from the set of files `image.*`.