You don't.
You're not required to use it on every image. It's a completely optional parameter that you add to individual images that might benefit from it.
You can use it on navigation icons that don't change size. Maybe in some of your boilerplate in the footer. Or in some sidebar content or a testimonial that you control. But if you have images of unknown size populating the middle of the page, don't use it on those.
The 1.2 kB icon in the footer is not really a problem, but the xxx kB article image some author uploaded with unknown sizes.
Those things will make my page jump around and will need to be lazy-loaded.
I doubt we’ll ever see them built into a browser, because all nice generalized things never get there.
The idea to set fixed dimensions feels like it comes from a time where we did designs with tables and "optimized" sites for 1024 x 768 pixel screen size.
That was the time when you could tell that this image should be displayed 200 x 200 px in size and nothing else. And it fit. One way or another.
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_cs...
Make no mistake, this is a silly problem to need to hack a solution for. So I would welcome lazy loaded images with space allocation before it's rendered with a responsive sizing.
Using js onresize event is a no-go, if JS is still needed the spec is worthless. Lazy loading images with JS worked before just fine, this has to be about not needing special JS for this feature.
No, parent is right: It's impossible to satisfy that recommendation, usually.
Screen relative units represent a percentage of the screen size (technically speaking it's the viewport really). You don't need to know how big the screen is; you're tell the browser to use, for example, 25% of the viewport height when you set something to be 25vh. If you want 4 images vertically that's really useful. That way the browser knows it needs to put a box 25% of the screen height in the DOM where the image will be loaded later so there's no layout thrashing.
Using js onresize event is a no-go, if JS is still needed the spec is worthless.
The parent suggested they would want to change the width and height attributes of the image when the user resizes their browser. That's exactly what the resize event is for. If you want to display a fixed size image you can use fixed width and height attributes. If you want the image to scale with the viewport size you can either use units that represent a relative size or you need to use JS to modify the attributes. Heck, you can even use media queries to mix and match and have fixed size in some devices and relative in others.
Lazy loading images with JS worked before just fine..
Except you needed JS to do it. With the new HTML spec you get the benefits of basic lazy loading without needing the additional weight of some JS code. That's good.
And that's before resizing anything.
And relative units don't fix this either as that information still misses the ratio of my image. If it's 100 vw, how high is it? I don't know this information without fetching the image, doing calculations and dynamically updating the DOM with that information.
I haven't been following the latest developments in CSS for a while, so maybe it's already possible to do this?