-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Add "auto sizes" for lazy-loaded images #4654
Comments
I've been planning to research the distribution of actual vs.
I'd be all for re-speccing @yoavweiss has told me, in informal conversation over the years, that the raciness that would result from this behavior would be Very Bad. Perhaps not platform compatible? Discuss. Another issue: what to do with images whose CSS @aFarkas probably has a lot of insight about this (and any other open questions or potential gotchas about making this a platform-native feature). |
I'm extremely happy to see this discussed. Here some thoughts:
Other issues I see:
Range request Calculating layout Calculating layout For determining the layout height all of the layout width applies the only thing here is that a fallback strategy to detect the right height ( At the end this is not a pure and only height based calculation but an aspect ratio based calculation which simply calculates a corrected width size. Post edits: sizes="100px, auto" I don't think that explicitly set Respecting It's also interesting wether you want to take CSS |
How do we know this will be guaranteed? One fear I have about this is that developers will just be lazy and lazy load all of their images just so they can avoid having to define |
We get to specify how this is to behave. If we want lazy images to not start loading until all pending stylesheets have loaded, then we require that (and write tests to verify). Web developers can lazyload all images today if they want to (and use |
Wow, also very happy this is discussed and it's really great that you guys responded to my doubts about current state of standard. Thanks @zcorpan for creating a separate thread for this issue! Idly wondering if My experience shows that And question is: how often browser does know image width and height for What if Instead of
And also, To sum up, let's be honest, from software architecture/maintenance point of view,
Honestly, I think the opposite could happen. Setting all images to |
Have no mind about a new attribute like |
Browsers today eagerly load images, and even speculatively load images (from the speculative parser), in order to improve performance. When Are things different today? I could take a guess, but I would prefer to look at data. Are there any studies for this already? An experiment could be to make a build of Chromium that lazy-loads all images, and compare performance metrics (preferably a metric that reflects when above the fold images are loaded) with a normal Chromium build. |
@zcorpan with the “Enable Lazy Loading” flag enabled in Chrome, it lazyloads all images by default. @dougsillars did some perf testing of this mode nine months ago, and found Speed Index scores to be ~500ms slower with lazyloading, vs without it, for one test page: https://dougsillars.com/2018/09/21/chromes-experimental-image-lazy-loading-flag/ In some informal personal testing, I've found that preloading an oversized image easily wins, across a broad range of connection speeds/latencies, over waiting for layout, and then loading an appropriately sized image. Loading CSS & doing layout takes a comparative eternity, vs preloading. |
Images without the |
@erkstruwe Oops! You're correct, & sorry for the misinformation. |
I agree If losing it means decreased performance, I would vote against it. Being difficult on the DX side is not an excuse if the UX benefits from it. There are extensions to check validity of |
I think there's a misunderstanding here. Yes, we want developers to specify |
I've always wondered why this is. |
This makes a lot of sense, especially when considering that choosing an appropriate size also happens for images (even eager ones) on resize/zoom/orientationchange after load. In these cases the browser already knows the layout and would know the appropriate image size. But the |
I would be quite against fully ignoring an explicitly set Again if The only use case I can think of is the short period of time where we have both autosizes supporting and non-supporting browsers for those browser the following syntax would be possible: |
I like the idea of Maybe call it |
@jakearchibald yeah, also see w3c/csswg-drafts#5889 |
A thought after a conversation on Twitter, today... Instead of minting a new In this model, authors who want smart auto-
If they haven't done both of these things (so: Then, if we want a new way to delay image loading until after the first layout but without caring about whether or not an the image is in the viewport, we mint a new A couple of examples...<img loading=lazy srcset="a 500w, b 1000w, c 1500w"> would end up with a source size based on its actual layout width (because <img loading=lazy sizes=500px srcset="a 500w, b 1000w, c 1500w"> would get a source size of 500px (specified sizes values win); and <img srcset="a 500w, b 1000w, c 1500w"> would end up with a source size of 100vw, as it currently does. |
As @aFarkas pointed out above, a keyword allows for better backcompat with legacy browsers. Or maybe you want A new |
Chromium is interested in and supportive of this feature. |
I'm not sure about 8007, but happy to keep discussing and evaluating the use case w/developer feedback. |
Fixes #4654. Fixup document conformance rules for the sizes attribute Remove 'being rendered to a visual medium'; only use the 'being rendered' definition Move the interpretation of 'auto' into the sizes parsing algorithm. Add 'loading' attribute state changes, 'being rendered' changes, and rendered width changes to relevant mutations. Allow auto as a bare entry in sizes with fallback entries after Fix markup error and add an example of sizes=auto in the image introduction Replace the 0px rendered width check with a computed value check for 'width' and 'min-width' Introduce 'concrete object size ignoring natural dimensions' Fix xref for 'concrete object size' Make 'auto' actually use the concrete object size ignoring natural dimensions width Reduce web compat risk by only watching for rendered width changes when using width descriptors
This adds a new module that will automatically enhance the `sizes` attribute of lazy-loaded images to support the new `auto` syntax. See: whatwg/html#4654 Fixes: #791.
From #3752 (comment)
The idea with
sizes
is:srcset
) + layout size of the image (sizes
). https://ericportis.com/posts/2014/srcset-sizes/The layout size information in
sizes
is redundant with layout information in CSS, but for images that are critical to initial paint it's necessary to have the information in the HTML.But for lazy-loaded images, CSS will usually be available before the image load begins. The browser could take the actual width of the image as specified in CSS, and use that as if it was the image's
sizes
.A syntax proposal is
sizes="auto"
, or omitting thesizes
attribute. Only allow this onloading=lazy
images.Issues:
loading=eager
images? Use100vw
(like today)?loading=auto
images? Depend on whether the UA decides to load it eagerly or lazily?The text was updated successfully, but these errors were encountered: