18

Add webp delivery via NGINX on settings page


Avatar
Cristian Uibar

Add webp support via NGINX with a toggle inside the site's settings page.

How this should work:
1. Sets $webp_suffix if the browser has the WebP capability:
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}

2. A location block inside the server config similar to this:
location ~* ^(/wp-content/.+).(png|jpe?g)$ {
set $base $1;
set $webp_uri $base$webp_suffix;
set $webp_old_uri $base.$2$webp_suffix;
set $root "";
root $root;
add_header Vary Accept;
try_files $webp_uri $webp_old_uri $uri =404;
}

A