Skip to content

Instantly share code, notes, and snippets.

@Eddy-Barraud
Created January 25, 2019 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eddy-Barraud/6adf36bc9cba649b470f8500aaaf68d5 to your computer and use it in GitHub Desktop.
Save Eddy-Barraud/6adf36bc9cba649b470f8500aaaf68d5 to your computer and use it in GitHub Desktop.
Serves webp images instead of jpg or png if supported by browser
http {
##
# WebP conf
##
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
##
# Minimal server
##
server {
[...]
location ~* ^/images/.+\.(png|jpe?g)$ {
root /home/www-data;
add_header Vary Accept;
try_files $uri$webp_suffix $uri =404;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment