Skip to content

Instantly share code, notes, and snippets.

@geekgonecrazy
Forked from sergejmueller/mime.types
Created February 21, 2014 18:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geekgonecrazy/9139621 to your computer and use it in GitHub Desktop.
Save geekgonecrazy/9139621 to your computer and use it in GitHub Desktop.
...
image/webp webp;
...
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