Implement auto-sizes for lazy-loaded images
Categories
(Core :: DOM: Core & HTML, enhancement)
Tracking
()
People
(Reporter: zcorpan, Assigned: ltenenbaum)
References
()
Details
(Keywords: dev-doc-complete, Whiteboard: [platform-feature], [wptsync upstream])
User Story
web-feature:sizes-auto webcompat-risk:low
Attachments
(1 file, 1 external file)
|
3.18 KB,
text/html
|
Details |
| Reporter | ||
Comment 1•3 years ago
|
||
The spec PR has landed now.
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
Updated•3 years ago
|
| Reporter | ||
Updated•2 years ago
|
| Reporter | ||
Comment 3•2 years ago
|
||
Changing component to Layout after discussing with :hsinyi.
auto-sizes is now enabled by default in Chrome https://bugs.chromium.org/p/chromium/issues/detail?id=1359051#c26
| Reporter | ||
Comment 4•2 years ago
|
||
This feature has now been adopted in WordPress 6.7: https://core.trac.wordpress.org/changeset/59008
I also found this PR for react-imgix from a GitHub search.
Chrome use counter is currently < 0.02% but I expect will rise as the above changes get deployed on sites and adoption spreads to other frameworks and libraries. https://chromestatus.com/metrics/feature/timeline/popularity/4750
Without supporting auto, we would likely fetch unnecessarily large images (at least for sites that use only sizes=auto without fallback on images).
Updated•2 years ago
|
| Reporter | ||
Comment 5•1 year ago
|
||
Chrome's use counter is now at ~0.6% of page loads, ~2.5% of httparchive pages.
Shopify has developed a polyfill: https://github.com/Shopify/autosizes
| Reporter | ||
Comment 6•1 year ago
|
||
Per :emilio, DOM: Core & HTML was correct, so changing back.
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Updated•1 year ago
|
Comment 7•10 months ago
|
||
Filed https://issues.chromium.org/issues/475195982 because Chromium does auto sizing even if auto isn't the first source-size.
Comment 8•9 months ago
|
||
Updated•9 months ago
|
Updated•8 months ago
|
Comment 9•8 months ago
|
||
As stated on the patch, I think we need to update mAutoWidth also outside of ObserveAutoSizesImage.
| Assignee | ||
Updated•8 months ago
|
Comment 10•7 months ago
|
||
Comment 11•7 months ago
|
||
| bugherder | ||
Comment 14•7 months ago
|
||
[Why is this notable]: New HTML feature
[Affects Firefox for Android]: yes
[Suggested wording]: A new auto value got introduced for the sizes attribute for lazy-loaded image elements with multiple image defined via srcset. This allows the browser to automatically select the right image based on the layout width of the image element.
[Links (documentation, blog post, etc)]:
https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/sizes
https://ericportis.com/posts/2023/auto-sizes-pretty-much-requires-width-and-height/
For documentation on MDN: The BCD already has an entry for the auto value (which needs to be updated). Though the page describing the sizes attribute referenced above should be updated to provide some explanation for how that value works, maybe including an example.
Sebastian
Updated•7 months ago
|
Comment 16•7 months ago
|
||
FF150 MDN docs work for this can be tracked in https://github.com/mdn/content/issues/43562
FYI, I'm still trying to fully understand exactly what I should document and where.
Most of the documentation is in <img> attribute sizes, which is cross linked from HTMLImageElement.sizes - it is fairly standard MDN practise to do most of the docs in the HTML element.
This seems pretty good. There is some lack of clarity on the default intrinsic size (it only mentions the wdith) and the reason you need to specify the width and height (i.e. I don't think it is because the intrinsic size of the image is not known - it's because it will be assumed to be a particular value based on the UA stylesheet if no other layout information is available.
Since the intrinsic size of the image is not yet known, width and height attributes (or CSS equivalents) should also be specified to prevent the browser from assuming the default image width of 300px.
My understanding of auto is that
- it allows the browser to determine the layout size of a lazy loaded image based on whatever the current layout information it has available.
- For a lazy loaded image the CSS for the page has already loaded, so any CSS or HTML layout information, including media queries have already been loaded. The benefit is that you don't have to specify what image to load based on media queries in the
sizesattribute and maintain this information in two places. - If your image wasn't lazy loaded the layout dimensions will be whatever you specify on the image HTML, or the 300 x 150px default "intrinsic layout" if you specified nothing.
@sebo, FYI one difference between FF and Chrome is that FF seems to dynamically check whether it has an optimal image and load an alternative if there is a better options - i.e. if you shrink the space for your image so another is a better match. Chrome seems to just load the image once and never recalculate.
Welcome any comments about the above you might have. Hoping to progress it on Friday.
Comment 17•7 months ago
|
||
(In reply to Hamish Willee from comment #16)
FYI, I'm still trying to fully understand exactly what I should document and where.
Most of the documentation is in<img>attributesizes, which is cross linked fromHTMLImageElement.sizes- it is fairly standard MDN practise to do most of the docs in the HTML element.
Oh, right! I missed that the auto value is actually documented in detail there. Though the description at the API page is very vague. I'd at least expect a short description of the syntax in one or two sentences besides referring to the sizes attribute on the <img> page. That could duplicate the introduction sentence of the attribute. At least that's how it's done for other more complex values like HTMLMediaElement.src.
My understanding of
autois that
- it allows the browser to determine the layout size of a lazy loaded image based on whatever the current layout information it has available.
- For a lazy loaded image the CSS for the page has already loaded, so any CSS or HTML layout information, including media queries have already been loaded. The benefit is that you don't have to specify what image to load based on media queries in the
sizesattribute and maintain this information in two places.- If your image wasn't lazy loaded the layout dimensions will be whatever you specify on the image HTML, or the 300 x 150px default "intrinsic layout" if you specified nothing.
That's also my understanding.
@sebo, FYI one difference between FF and Chrome is that FF seems to dynamically check whether it has an optimal image and load an alternative if there is a better options - i.e. if you shrink the space for your image so another is a better match. Chrome seems to just load the image once and never recalculate.
Thank you for the hint! I didn't check that yet, but I guess, user agents are allowed to optimize their algorithms for either image quality or performance, in that case. @Hamish Did you already check that difference?
Sebastian
Comment 18•7 months ago
|
||
Thanks Sebastian. I've attempted to to this in https://github.com/mdn/content/pull/43684 - would love your review on the changes - if you have time?
Mostly it is better cross linking and a little structure in the <img> doc, but I also added an example in the other doc.
@Hamish Did you already check that difference?
Do you mean "did I check the spec to confim this is OK?". No, but looking now https://html.spec.whatwg.org/multipage/images.html#reacting-to-environment-changes it appears that this is at the browser discretion
The user agent may at any time run the following algorithm to update an img element's image in order to react to changes in the environment.
I was slightly wrong on the differences.
- Chrome will load a bigger images if you increase the size of a contained image, but it won't reload a smaller element (while FF will).
- The other main difference is that FF does not appear to lazy load - it loads all the images as soon as the page appears.
This isn't testable using the example I created in the PR here because the images aren't loading. But the same example immediately shows the images have loaded if you test locally (in the on-page log)
Comment 19•7 months ago
|
||
(In reply to Hamish Willee from comment #18)
Thanks Sebastian. I've attempted to to this in https://github.com/mdn/content/pull/43684 - would love your review on the changes - if you have time?
I've provided some feedback now. (Though Chris already did most of what I would have had remarks on.)
@Hamish Did you already check that difference?
Do you mean "did I check the spec to confim this is OK?". No, but looking now https://html.spec.whatwg.org/multipage/images.html#reacting-to-environment-changes it appears that this is at the browser discretion
Yes, that's what I meant. Thanks for pointing to the specification!
Sebastian
Updated•7 months ago
|
Updated•2 months ago
|
Description
•