diff --git a/global/http.conf b/global/http.conf index faf1e6d..fc7d426 100644 --- a/global/http.conf +++ b/global/http.conf @@ -5,4 +5,10 @@ sendfile on; tcp_nopush on; # Don't wait to send data in keep-alive state. -tcp_nodelay on; \ No newline at end of file +tcp_nodelay on; + +# Check if web browser supports WebP images +map $http_accept $webp_suffix { + default ""; + "~*webp" ".webp"; +} \ No newline at end of file diff --git a/global/server/static-files.conf b/global/server/static-files.conf index da52a95..e4aba67 100644 --- a/global/server/static-files.conf +++ b/global/server/static-files.conf @@ -8,8 +8,14 @@ location ~* \.(?:rss|atom)$ { expires 1h; } +# Use the WebP version of converted PNG/JPEG images +location ~* ^.+\.(png|jpe?g)$ { + add_header Vary Accept; + try_files $uri$webp_suffix $uri =404; +} + # Caches images, icons, video, audio, HTC, etc. -location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc)$ { +location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|mp4|ogg|ogv|webm|htc|webp)$ { expires 1y; access_log off; }