-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
use_native breaks lazy loading of videos #527
Comments
Hey @saschaeggi , As you can read in the API documentation, the Are you suggesting that this LazyLoad library should detect if the browser is supporting native lazy loading for videos, and in case do the same thing it does for images and videos? |
Or are you suggesting that this LazyLoad library should just copy the |
With the current version of the script, the solution you should adopt is to use two different instances of LazyLoad, one for videos, one for the rest. // Instance using native lazy loading
const lazyContent = new LazyLoad({
elements_selector: "img.lazy, iframe.lazy",
use_native: true
});
// Instance without native lazy loading
const lazyBackground = new LazyLoad({
elements_selector: "video.lazy",
// DON'T PASS use_native: true HERE
}); Now if I think of an enhancement of the script with an auto-detection of the native lazy loading for video, the question is: What should the script do when it runs on a browser that doesn't support native lazy loading for videos, and the user passed
If you ask me, I'd probably go for option 1. In other words, the script user should detect if the browser supports native lazy videos, and if yes, it passes the For example: const supportsNativeLazyVideo = () => "loading" in HTMLVideoElement.prototype;
if (supportsNativeLazyVideo()) {
// Single instance using native lazy loading on images, videos and iframes
const lazyContent = new LazyLoad({
use_native: true
});
}
else {
// Double instance using native lazy loading on images and iframes,
// and JS driven lazy loading on videos
const lazyImgIframe = new LazyLoad({
elements_selector: "img.lazy, iframe.lazy",
use_native: true
});
const lazyVideo = new LazyLoad({
elements_selector: "video.lazy"
});
} What do you think @saschaeggi? |
Hey @verlok
So yes, your idea of using two instances could be the solution to my problem 🙂 |
Hey, Great, I'm already proceding that way. Stay tuned. |
Pleasure is all mine |
Solved in 17.4.0! Just released. |
@saschaeggi are you satisfied with the new version? |
Yes works great, thanks a lot for your effort! |
Hey @saschaeggi, If you’re happy with my support, the documentation and the effort I’ve been putting on this project in the latest years, I hope you might want to buy me a coffee to show your appreciation. Or sponsor me, if you're a fan. Open-source software is great for everyone, but it takes passion and time to grow and evolve. Thank you for thinking about it. Have a nice day! |
I know exactly how hard it can be to maintain an Open Source project, as I maintain multiple of them myself. |
Thanks, @saschaeggi |
Describe the bug
When the native option is used, videos won't lazyload, it looks like those will get ignored. data-src doesn't transform to src, nor gets the loaded class attached.
To Reproduce
<source data-src="...">
Video won't load at all. If use_native is set to false, it works.
Expected behavior
Allow videos to work together with use_native
LazyLoad version
Version 17.3.2
Desktop (please complete the following information):
All browsers
Smartphone (please complete the following information):
All browsers
The text was updated successfully, but these errors were encountered: