Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Automatic format conversion based on user-agent #253

Open
manoj-makkuboy opened this issue Mar 7, 2019 · 4 comments
Open

Comments

@manoj-makkuboy
Copy link

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 manoj-makkuboy changed the title Automatic format conversion based on user-agent Feature Request: Automatic format conversion based on user-agent Mar 7, 2019
@jbergstroem
Copy link
Contributor

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.

@Dynom
Copy link
Collaborator

Dynom commented Mar 11, 2019

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.

@jbergstroem
Copy link
Contributor

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.

@imfantuan
Copy link

Try "Vary: accept"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants