Skip to content

Conversation

guaca
Copy link
Contributor

@guaca guaca commented Nov 15, 2022

Description

According to the 2022 Web Almanac, 9.8% of mobile pages with image-based LCP set loading=lazy on them. And 8,8% use custom lazy-loading.

The current snippet only tracks lazy-loaded images using the native loading="lazy" attribute. Hence, it's only useful for 52% of mobile pages using any lazy-loading approach on LCP images.

Proposed solution

With this update, the snippet also tracks lazy-loaded images via JS, looking for "data-src" attributes.

I've also updated the return statement to return an array with all the lazy-loaded elements or false if no image above the fold was lazy-loaded.

Copy link
Owner

@nucliweb nucliweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome 🤩

Thank you @guaca

@nucliweb nucliweb merged commit 77388d9 into nucliweb:main Nov 15, 2022
@verlok
Copy link
Contributor

verlok commented Nov 15, 2022

Lovely. I’ve also seen lazy loaded images with data-origin in old versions of jQuery LazyLoad, which have been migrated to new LazyLoad libraries, like my vanilla-lazyload by changing the default options of the library.

So probably also adding data-origin would be more complete, but… old things, I’m not sure.

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

Labels

None yet

3 participants