Created
November 27, 2013 09:00
-
-
Save sergejmueller/7672727 to your computer and use it in GitHub Desktop.
Nginx: Detecting WebP support with Header Vary Accept. Filename format: image.jpeg / image.webp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
image/webp webp; | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location ~ (.+)\.(png|jpe?g)$ { | |
if ( $http_accept ~* webp ) { | |
set $webp "A"; | |
} | |
if ( $request_filename ~ (.+)\.(png|jpe?g)$ ) { | |
set $file_without_ext $1; | |
} | |
if ( -f $file_without_ext.webp ) { | |
set $webp "${webp}E"; | |
} | |
if ( $webp = AE ) { | |
add_header Vary Accept; | |
rewrite (.+)\.(png|jpe?g)$ $1.webp break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment