-
Notifications
You must be signed in to change notification settings - Fork 87
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
lazyload skip first n images does not work on <picture/ <source elements #381
Comments
Ciao @frutta i did a npm module that is not affected by the common LCP issues and can lazyload videos and backgrounds, i made it following the westonruter advices to get a good results lighthouse rankings (see the slack thread) https://www.npmjs.com/package/auto-lazyload Feel free to test it and use as you want if you think that is better than lazysites (that is a bit outdated, isn't it? 😉) as long your plugin is free as it has always been :) |
if needed i can explain how it work in detail but TLDR:
|
interesting @erikyo .. is this in use already somewhere? standalone or as part of another plugin? would love to see feedback on it from other users :) |
You can disable the lazyload script adding it's a script I made a couple of weeks ago because some customers complained about the performance of some landing pages we made with Gutenberg, which are beautiful but have some critical points that I solved with the first script I posted in the slack conversation with Weston Router. The critical points are about backgrounds and videos that we use intensively but as I said with some drawbacks like the decreased performance
it's a simple js script, as vanilla-lazyload or the lazySites and actually can be used as iife (as in the website i shared) or as a npm module, anyhow in the wp context i believe it's better the iife version since it's a very tiny script and we wont leverage of the cool stuff of the es modules like the tree-shaking
Me too but somehow i have to propose it otherwise no one will even know it exists. I hope someone who passes by here will try that module and give a feedback. EDIT: With the last version you can avoid issue like this one in the demo page that holds a slider/swiper script dynamically loaded (e.g. This issue now can be fixed easily using This is the gain that can be achieved (obviously on pages with only images the gain is marginal since wp already deal with that using loading="lazy") |
I am writing to you after seeing on slack #performance that your plugin has been 'named' because of lazysites (see. this file shared there) If you really don't like the futuristic implementation i made (joking😉), I think other implementations were better, e.g. vanilla lazyload that supports backgrounds, has been written in modern js, smaller/faster etc. (ps i'm a contributor so I might be biased 😅). |
re. background images, the issue is not with
which AO+lazysizes can indeed do, but rather with
where the problem is that AO (currently) does not "know" .xyz has a background-image (AO does not look for relation between HTML & CSS (or JS) so it does not alter the HTML or CSS meaning lazysizes has nothing to pick up here :-/ |
@futtta you can hook to the event "beforeLazyUnveil" with a function like this one: document.addEventListener( 'lazybeforeunveil', (e) => {
const bg = e.target.getAttribute('data-bg');
if (bg) {
e.target.style.backgroundImage = `url(${bg})`;
}
}); this way it should work exactly the same as for images and you will not need to create a css class for it |
the issue here is the div does not have a style attribute with the image as background-image, so AO doesn't "know" there is a data-bg to be added, as that URL is set in the linked CSS-file, not in the HTML :) |
ah yes, you are right... i that case would not work 😢. However I believe that gutenberg uses the style, especially in that critical case of the cover. In that case it could help a lot because they are often very large images |
see https://wordpress.org/support/topic/lazy-loading-bug/
The text was updated successfully, but these errors were encountered: