Sorry cshoredaniel I meant frjo’s code. I must be in an altered state of consciousness because I perceived your messages as coming from one person
Now it works frjo, your code did the trick:
Ok technically my issue is solved, I wrote what I wanted.
But as far as getting background LQIP images and not having any CLS (eventhough my lighthouse score is 100% and 97%), it’s done yet. I don’t see the background.
Any idea how I can check that it appears ? Can I deactive the img object somehow but keep the css style (background) associated with it ?
So as to know if the background styling is even rendered.
Use DevTools ‘device emulation’ and enabling throttling to ‘slow 3G’ and do a no-cache refresh (typically by pressing the Shift key will clicking the refresh button). You should briefly see the background image.
A way to check that doesn’t use the live image tag would be the apply the same style to a <div> on which you set a width and height. That should show the background image.
The first tests the actual HTML you will use, the second is not time sensitive but is not the actual HTML.
DevTools options may allow discarding foreground but not background images, but I’ve never looked for that, so don’t really know.
it should logically be ideal but does not work for some reason. inline or external style, with “0 0” or “5% 5%”, no change. Removing the src and srcset attributes also do not make the background appear. not even an empty place.
With width:fit-content in img, what appears is usually smaller than with width:100%, but it’s always very small anyway. the sizes html attribute or width and height are not read, instead it seems to always fit something like the intrinsic size of the background, not what I tell him to. I tried several different height and width. I thought html attributes took precedence over styling ?
I try with a firefox-based browser…
background images still don’t work as LQIP, it seems that loading=lazy delay loading the entire object, background included. I could verify that the CLS persists.
I’ll see with the forum member who wrote those LQIP modules.