Skip to content

Instantly share code, notes, and snippets.

@thatryan
Created March 27, 2020 17:58
Show Gist options
  • Save thatryan/82c2017aede958a61172bf3f597a3b72 to your computer and use it in GitHub Desktop.
Save thatryan/82c2017aede958a61172bf3f597a3b72 to your computer and use it in GitHub Desktop.
webp nginx
location ~* ^(/.+)\.(jpg|jpeg|jpe|png|gif)$ {
add_header Vary Accept;
if ($http_accept ~* "webp"){
set $imwebp A;
}
if (-f $request_filename.webp) {
set $imwebp "${imwebp}B";
}
if ($imwebp = AB) {
rewrite ^(.*) $1.webp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment