Skip to content
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

Auto-sizes for lazy-loaded images in HTML #650

Closed
zcorpan opened this issue Jun 14, 2022 · 3 comments · Fixed by #746
Closed

Auto-sizes for lazy-loaded images in HTML #650

zcorpan opened this issue Jun 14, 2022 · 3 comments · Fixed by #746

Comments

@zcorpan
Copy link
Member

zcorpan commented Jun 14, 2022

Request for Mozilla Position on an Emerging Web Specification

Other information

@emilio
Copy link
Collaborator

emilio commented Jan 18, 2023

My main concern with this proposal is the behavior for lazy images that might or might not be in the cache...

In particular, if a lazy-loaded image is on the cache, right now we use it eagerly (and the image is never in the lazy state).

That means, IIUC, that given the current state of the proposal, if the sizes=100vw image is in the cache we'll use that, otherwise the image will enter into the lazy state and eventually select a source using sizes="rendered-size".

This has two effects:

  • An image might have a different source depending on timing and cache state (which is a bit surprising but might be ok, since the sizes=100vw image is intended to be larger).

  • An image with sizes="auto" might flicker if moved or re-inserted in the DOM (which I think it might not be ok). In particular, any time you have two different sizes, one that is actually used, and one that would get selected with sizes=100vw, we'd check the cache, find that the sizes=100vw image is not in the cache, enter the lazy state and eventually select the other source.

I'm not sure the second point is a deal breaker, as long as we're aware of it and it's tested properly in WPT (the available check is tested in html/semantics/embedded-content/the-img-element/image-loading-lazy-available.html). But I feel like it's going to bite somebody :/

@zcorpan
Copy link
Member Author

zcorpan commented Jan 18, 2023

The spec only uses the "list of available images" if the img element has a non-empty src and does not use srcset and does not use picture, see step 4 in https://html.spec.whatwg.org/#update-the-image-data

That is, <img srcset="a 100w, b 200w" loading=lazy> should always be lazy even if one or several of the images are cached. Not sure if this case is tested in wpt currently.

@zcorpan
Copy link
Member Author

zcorpan commented Feb 14, 2023

I discussed this with @emilio and there are still concerns about flickering, though that's an issue with how the spec loads images before this feature, too. It seems possible to address this in the spec later. Our position is "positive". I'll submit a PR for a dashboard entry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants