Skip to content

Instantly share code, notes, and snippets.

@nileshgr
Created July 9, 2013 15:04
Fallback for WebP serving using nginx So you want webp files to be named as .jpeg.webp in your htdocs. You link to images in your HTML as .jpeg. Nginx will detect if browser supports webp and automatically serve webp or jpeg (File extensions do NOT decide the type).
if ($http_accept ~* "webp") {
set $webp "true";
}
if (-e $request_filename.webp) {
set $webp "${webp}-local";
}
if ($webp = "true-local") {
rewrite (.*) $1.webp last;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment