I am using ShortPixel to create WEBP images, with named image.webp and are saved in the same folder as image.jpg.
- I added this in etc/nginx/conf.d/webp.conf:
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
and added include etc/nginx/conf.d/*.conf
in nginx configuration file.
- Added this in etc/nginx/conf.d/site.conf
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 "FULL PATH OF wp-content PARENT";
root $root;
add_header Vary Accept;
if ( !-f $root$webp_uri ) {
add_header X_WebP_SP_Miss $root$webp_uri;
}
try_files $webp_uri $webp_old_uri $uri =404;
}
Check with nginx -t
, everything correctly. However in devtool/network tab, images type still jpg. Why is that?