Problem/Motivation
Mat Marquis published an article https://piccalil.li/blog/the-end-of-responsive-images/ about the broader availability of the auto keyword for the sizes attribute on the img element.
Before that, the sizes attribute required a lot of manual adjustment to align the sizes available in the srcset with the actual layout of a page/site to minimize the data transferred on every page load. above the fold that problem still applies, but for any lazy loaded image with the auto keyword applied, it is now up to the browser to decide which image best to load - the entire layout context is already available to them at that point.
Steps to reproduce
Proposed resolution
Add support for the auto keyword on lazy loaded images.
In regard to browser support, Blink, Gecko, and Webkit all have added support to it. In regard to older browser Mat Marquis writes:
Well, if you’re worried about browser support, don’t be — upon encountering the string “auto” at the start of a sizes attribute, any browser with support for it will say “figure it out myself; got it,” ditch the rest of the sizes attribute, and move on — browsers without support will throw the meaningless-to-them auto value out and continue on to the rest of attribute as usual.
So it is a progressive enhancement scenario with no need for any polyfill or the need to wait until the requirements listed in https://www.drupal.org/docs/getting-started/system-requirements/browser-... are full-filled.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3587098
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
bronzehedwick@rkoller I added an MR to add the
autokeyword tosizesfor any responsive image with anloadingattribute oflazy.The MR also normalizes spacing around the
sizesitems.Open to any and all feedback!
Comment #5
smustgrave commentedProbably should have test coverage for new features
Comment #6
bronzehedwickMakes sense @smustgrave! I pushed a fix that adds some unit and functional tests.
Comment #7
rkollerThank you for the MR @bronzehedwick and apologies for the belated comment, but figuring out the actual testing of the MR took me longer than I've hoped and anticipated. First I ran into the question which theme to pick and then into some odd results due to the fact that by default I start testing things in Safari first. I quickly outline the test setup.
I've installed a fresh Drupal site with the
mainbranch using thedemo_umamitheme. Aside the default responsive image styles:I've also added
I've only focused on the responsive image style the smaller images on the front page are assigned to. it also has to be noted that
demo_umamiuses100vwfor thesizesattribute, which might caused that way bigger images than expected were picked. For testing i took the following approach. I've opened browser windows inEach of windows had,
960pxin width so the multicolumn layout is being used, and resized the windows in height so that only the hero image is being displayed, and the rest of the images beneath the fold are getting lazy loaded.For every browser window I first deleted
sites/default/files/styles, randrush cr, reloaded the page in that browser window by clicking the reload button, documented the content ofsites/default/files/styles, scrolled the page to the bottom, and then recheckedsites/default/files/styles. All browser windows were on a none retina screen when the tests were assessed:Without the MR checked out:
Safari 26.5 (21624.2.5.11.4)
After load
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
oatmeal-fruit-syrup-topping.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Safari Technology Preview Release 243 (WebKit 22625.1.15.19.1)
After load
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
oatmeal-fruit-syrup-topping.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Firefox 151.0
After load
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
oatmeal-fruit-syrup-topping.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Firefox Developer Edition 151.0b10 (aarch64)
After load
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
oatmeal-fruit-syrup-topping.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Microsoft Edge Version 148.0.3967.54
After load
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
oatmeal-fruit-syrup-topping.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
With the MR checked out:
Safari 26.5 (21624.2.5.11.4)
After load
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
oatmeal-fruit-syrup-topping.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Safari Technology Preview Release 243 (WebKit 22625.1.15.19.1)
After load
small_500x333
oatmeal-fruit-syrup-topping.jpg.avif
small_3_2_2x_1000x666
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Firefox 151.0
After load
small_500x333
oatmeal-fruit-syrup-topping.jpg.avif
smallest_3_2_2x_400x266
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Firefox Developer Edition 151.0b10 (aarch64)
After load
small_3_2_2x_1000x666
oatmeal-fruit-syrup-topping.jpg.avif
smallest_3_2_2x_400x266
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
Microsoft Edge Version 148.0.3967.54
After load
small_500x333
oatmeal-fruit-syrup-topping.jpg.avif
smallest_3_2_2x_400x266
borscht-with-pork-ribs-umami.jpg.avif
chili-sauce-umami.jpg.avif
crema-catalana-umami.jpg.avif
thai-green-curry-umami.jpg.avif
After scroll
no change
So in summary it looks like the
autoattribute is only available in the tech preview but not the stable version of safari so far based on the results from the tests above. While in the stable versions of the Developer Edition of Firefox and Edge browsers are doing things as expected with theautoattribute active. That rather large images are still loaded, might be due to the usage of100vwfor thesizesattribute in Umami; i dont wanted to start juggling with thosesizesvalues, those are regularly breaking my brain. Not sure what others think after testing on their own, but for me that looks good.The only odd thing, that images beneath the fold got loaded on page load and not lazy loaded on scroll in all four browsers i've tested in, even though the display settings have the
lazyoption activated for the image media itemComment #8
bronzehedwickThanks for the detailed tests @rkoller! The results are really interesting. The
lazyoddity seems to happen with or without this MR, correct? I was able to see images lazy loading correctly on a plain HTML site I whipped up to test. Maybe it's a separate issue with Umami?Comment #9
rkolleryes, at least in my test in #7, no matter if the MR was checked out or the main branch, all images were loaded on page load already and none got actually lazy loaded.
i've just tested on the main branch with the standard profile within olivero. i've quickly created a content type with just a media image field (lazy loading active). there the lazy loading worked mostly. one post with an image was above the fold and three underneath, on page load the first two images already got loaded on scroll then the other two. but i have to test more in depth tomorrow or on the weekend.
Might have to do with the distance from viewport threshold referenced in the following article https://web.dev/articles/browser-level-image-lazy-loading#distance-from-... - but that was just the result of a brief search. not sure if that was the reason. but still odd that it hasnt worked in umami at all in my tests. will see tomorrow or on the weekend.
but in general i dont think that image not getting lazy loaded is related to this issue in any way. it might have to do with umami as you've suspected but with adding the auto attribute, otherwise lazy loading would have worked with the main branch checked out.
Comment #10
catchJust to say the distance from viewport threshold on chrome is very big and varies by device type it can be thousands of pixels so a full screen height or more - usually means you need a very, very long page before images actually don't get loaded. Although the 'lazy' is I still think used to allow the browser to prioritise which images and assets to load even if it ends up loading everything.
Comment #11
bronzehedwickThat makes sense @catch. I can see lazy images loaded much more quickly in Chrome than in Firefox or Safari.
Comment #12
rkollerthanks @catch. i have taken another look at the Chromium source that was linked in that web.dev article. those pixel values are indeed huge, with a connection speed set to offline the value is at 8000px .... so no wonder everything was loaded at once in most cases (i guess other browsers engines are not much different in that regard) ... aside that detail things look good from a manual testing perspective. I've also tested, the
autokeyword is not getting added whenloadingis set toeager. so in case tests look good this issue looks good from my point of view.