imaginary icon indicating copy to clipboard operation
imaginary copied to clipboard

Feature Request: Automatic format conversion based on user-agent

Open manoj-makkuboy opened this issue 6 years ago • 4 comments

How about support for automatic format conversion based on user agent. Webp seems to be the preferred format on supported browsers like chrome. So, wouldn't it be nice to have an option which enables the automatic format conversion based on user-agent (browser)

manoj-makkuboy avatar Mar 07 '19 10:03 manoj-makkuboy

I do this in layers in front of imaginary to keep it "intentionally stupid". Part 1 is using skipper to modify the route back to imaginary. In front of that I have a bit of logic in my http cache to be able to mutate caches (with the same url) based on just this.

jbergstroem avatar Mar 08 '19 16:03 jbergstroem

I see several complications with this approach, for those who are using a CDN. Content-Negotiation can make for a terrible cache strategy (even the order of the Accept header will result in many cache-misses) or terrible cache handling (Serving webp because it was requested first and leaving every other browser after that with an unsupported image).

However I can understand that there are situations where this would be beneficial especially when the content-negotiation can be done properly. HTTP has a pretty neat thing for content-negotiation, the HTTP Accept header. The User-Agent isn't ideal.

This would be a rather simple change:

  • A parameter indicating that the Accept header may be used for figuring out the best type
  • Reading out the Accept header and determine the most suitable type to return.

PR welcome.

Dynom avatar Mar 11 '19 19:03 Dynom

I see several complications with this approach, for those who are using a CDN. Content-Negotiation can make for a terrible cache strategy (even the order of the Accept header will result in many cache-misses) or terrible cache handling (Serving webp because it was requested first and leaving every other browser after that with an unsupported image).

You shouldn't create a cache key blindly. It took me a while to get this right, but it serves me very well and I account for a few things based on either client hints via headers or polyfilled as cookies.

jbergstroem avatar Mar 12 '19 00:03 jbergstroem

Try "Vary: accept"

imfantuan avatar Feb 13 '20 14:02 imfantuan