Time and again working on big web applications we customize files based on user’s platform, and their preferences. We can send different files to legacy browsers, different CSS and JS to mobile browsers depending on their form factor, different images to accomodate bandwidth requirements, and so on.
This post was prompted by my desire to serve sprites produced by
as WebP images to WebP-capable browsers falling back to “classic” image formats for the rest using nginx.
While it is hardly a new topic, I was not satisfied with existing solutions, which all used
instead of simpler methods.
Obviously the core solution can be used to serve almost any file conditionally, not only images, but all examples will be about WebP.