igrigorik/webp-detect — pull request #5 by uhop (2014-12-01 20:07:45+00:00)
Title: Switched nginx to map/try_files.

Sorry for the delay, but better late than never.

Notes:

1. While the original code didn't include a special processing for MSIE, it was mentioned in [the twit](https://twitter.com/igrigorik/status/525034376665763840), so I added it using your description of a desired functionality in the blog post as a guidance.
1. `$msie` variable of `ngx_http_browser_module` is used to detect MSIE. The module is included in nginx by default, no need to recompile anything.
2. `$msie` fails to detect IE11 as MSIE. OTOH, the original code fails to do it as well. Oh, well. If it is critical, we can use a custom detection with a regular expression.
2. The code doesn't check explicitly if a `.webp` version exists relying on `try_files`. As a side-effect, `Vary: Accept` is set for all modern browsers (excluding MSIE). In my case it is a desirable behavior:
1. No need to touch a file twice, which speeds up the preferred case of modern browsers supporting WebP.
2. It rarely makes sense to use WebP selectively. Personally I convert files to WebP automatically en mass anyway.
3. I have no idea about the proxy business, or what it does. Consequently I didn't touch it.
1. Personally I prefer to serve static assets without extra proxying. If I generate something by an external application, I usually prefer take care about the response there instead of having a response logic all over the place. But who knows what people do. OTOH, we suppose to show best practices.
2. The proxy code used `$webp` variable, but I couldn't find where it is set. Judging by the context it was supposed to be `$webp_accept`, so I changed it. Please double-check.
4. I added references to relevant blog posts, which explain details.
5. I added a comment advising to add WebP to `mime.types`. This file is not included in the repository, and with the default one, WebP files will be downloaded rather than shown.

Let me know, if you have any suggestions or concerns.