News for hackers. Stuff that matters.
Re:Optimizing Images with the HTML Tag by gildas on Sunday October 30, 2022 @02:53PM (#33397407)
> I don’t think there’s a perfect answer. You simply cannot predict with 100% certainty what the browser would choose. But you can get a good approximation by parsing the User-Agent header

Isn't it the purpose the the "Accept" HTTP header? For example the last version of Firefox sends "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,/;q=0.8" when fetching a page.

Re:Optimizing Images with the HTML Tag by geoffeg on Sunday October 30, 2022 @03:41PM (#33397864)
I've been surprised lately by the number of people that don't know about or understand HTTP headers. One discussion I saw was on a project that was trying to decide what language to serve a webpage in. They spent a good amount of time choosing a geo-location provider and library and then deciding what language to default to for locations that often had multiple languages. I asked why they didn't just use the Accept-Language header, which they weren't aware of.
Re:Optimizing Images with the HTML Tag by dmitriid on Sunday October 30, 2022 @04:03PM (#33398092)
Re:Optimizing Images with the HTML Tag by wwalexander on Sunday October 30, 2022 @04:39PM (#33398418)
Same thing with core UNIX commands, and so many other areas. We are doomed to incessantly reinvent the wheel and turn versatile abstractions into single-purpose complications. One must imagine Sisyphus happy.
Re:Optimizing Images with the HTML Tag by levymetal on Sunday October 30, 2022 @05:01PM (#33398635)
Google famously uses geolocation to set language instead of Accept-Language. They have their reasons, which I disagree with.

https://news.ycombinator.com/item?id=30638590

Re:Optimizing Images with the HTML Tag by CamelRocketFish on Tuesday November 01, 2022 @02:58PM (#33425813)
Agreed, this experience is terrible.
Re:Optimizing Images with the HTML Tag by Theodores on Sunday October 30, 2022 @05:38PM (#33399010)
Exactly. Just have jpg in the code and serve webp based on header. Problem solved.

If you can do avif with better results than webp then do that.

You can also vary on the data save if you are really keen.

Re:Optimizing Images with the HTML Tag by jbverschoor on Tuesday November 01, 2022 @09:26PM (#33430330)
You’d need to serve the proper resolution too
Re:Optimizing Images with the HTML Tag by capableweb on Sunday October 30, 2022 @02:59PM (#33397461)
Yup, exactly. Seems like a strange omission. Using the <picture> tag should make that obsolete though, as the browser can chose which image to fetch without involving the backend, maybe that's why?
Re:Optimizing Images with the HTML Tag by unilynx on Sunday October 30, 2022 @03:48PM (#33397936)
You can't easily use that with a plain* CDN though - you would need to add a Vary: Accept header and cache misses will increase as every variant of Accept: will cache a different version

* it seems fixable with things like Lambda@Edge and I wouldn't be surprised if a smart CDN which already does on-the-fly image compression had implemented this too

Re:Optimizing Images with the HTML Tag by selcuka on Sunday October 30, 2022 @09:13PM (#33400885)
You can't parse the User-Agent header (which is the suggested method in the article) with a plain CDN either, so that argument is moot.