Alright, there’s some progress on this. Or perhaps not.
Turns out that srcset
adjusts for dpi because the image versions provided are in actual pixels and the browser picks whatever it likes.
so;
<img
src="default.webp"
style="width: 100%"
srcset="low.webp 400w, med.webp 800w, high.webp 1000w, high1.webp 1100w, high2.webp 1200w, high3.webp 1400w, toohigh.webp 4000w"
alt="Lose" />
On desktop, you can get all versions by resizing. On my android phone (396px), i get the 1100 version (x2.73, actual res 1080). On iphone (390px) i get 1200 version (x3, actual 1170).
This looks good until you discover all browsers always load the 4000 version as well. Which is silly. They get the biggest picture, ignore it and show a smaller one.
Also explained here.
So i try adding some media descriptors eg;
sizes="(max-width: 390px) 390px,
(max-width: 400px) 400px,
(max-width: 1100px) 1000px,
(max-width: 1200px) 1100px,
(max-width: 1300px) 1200px,
(max-width: 2000px) 1400px,
4000px"
But it still loads the biggest picture as well as the one it finally choses. I can put less in the media sizes
list, but it will still load the largest specified as well as the one it finally uses!
This is obviously rubbish. If you have answer, or a suggestion, I’m happy to test it.
Then there’s using picture
maybe like this:
<picture>
<source srcset="low.webp" media="(max-width: 400px)">
<source srcset="med.webp" media="(max-width: 800px)">
<source srcset="high.webp" media="(max-width: 1000px)">
<source srcset="high1.webp" media="(max-width: 1100px)">
<source srcset="high2.webp" media="(max-width: 1200px)">
<source srcset="high3.webp" media="(max-width: 1400px)">
<source srcset="toohigh.webp" media="(max-width: 4000px)">
<img src="default.webp" alt="lose!">
</picture>
But then i aways get the smallest because 400px is css pixels > 396 > 390. So basically, you can only use picture
if you manually accommodate DPI. For example as x2, x3 etc, as done here.
Which is no answer either.
Here’s my res test link. The pictures are different with the sizes on them for amusement.
This whole debacle is another reason to avoid HTML and do everything yourself.