-
Notifications
You must be signed in to change notification settings - Fork 52
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
Cap images for > 2x DPR screens and use quality to reduce file size #202
Comments
Hi. Thanks for opening this. I read your blog a month or so ago. Do you think that it would be possible to automate that approach, with support for the different layouts? Right now fixed, full width and constrained each have their own rules and sizes, and any new algorithm would need that too. |
Thanks for writing that article and sharing your research. My biggest concern about implementing this (or even the other |
We just launched |
An update from my side: I spoke to Yoav Weiss from Google at PerfNow Amsterdam, and Chrome will try to get the 2x cap rolling again in 2024, probably via an attribute on the
I 100% agree on that part. 'My' method, or any method that hacks around
I think it's tough, maybe do-able (but hacky), maybe not. I also talked to other folks about this at PerfNow, let's see what the community comes up with.
Cool, so you cap to 2x in the build (or compilation) step, right? |
Yeah. We got the idea from Next.js Image, which does the same thing |
Nice! |
The srcsets that we generate for If there was a way to do this all programatically in a way that supports the different layout types then I'd definitely be interested in a contribution to support it. |
Describe the bug
The used
srcset
technique makes high-DPR devices download too big images, see the screenshots below.At a screen width of
390px
, for a3x
DPR screen (e.g. iPhone 12), it should download e.g.750w
, not800w
. For the example image, the difference is80.8 kB
->77.6 kB
.While
4.2 kB
is not the end of the world, I do think the images are not compressed enough. Most image CDNs listed here support a quality parameter, which would drastically reduce the file size. See: https://jakearchibald.com/2021/serving-sharp-images-to-high-density-screens/If you wonder why I say the iPhone 12 should download
750w
and not800w
: https://www.andreaverlicchi.eu/capping-image-fidelity-2x-minimize-loading-time/ and a study from Cloudinary: https://observablehq.com/@eeeps/visual-acuity-and-device-pixel-ratio.We reach a point where humans no longer see the difference, thus the additional resolution are wasted kB's. Yoav Weiss proposed to cap at
2-2.2x
in Chromium: https://bugs.chromium.org/p/chromium/issues/detail?id=1125973. So for3x
DPR screens, or even4x
DPR, loading2x
is enough to have very crisp image.To Reproduce
Steps to reproduce the behavior:
$0.currentSrc
to find which image is currently renderedExpected behavior
2x
dimensionsScreenshots
Additional context
I've written a lengthy blog post here about this topic: https://kurtextrem.de/posts/modern-way-of-img.
<img srcset>
sadly makes this a bit complicated if you compare it to the<picture>
tag like used by Jake Archibald, but it is definitely possibly to control which image is loaded by using a more complexsizes
attribute (which I callboolean <img>
as it toggles the image around like a boolean).The text was updated successfully, but these errors were encountered: