vanilla-lazyload is a JavaScript lazy loading library and viewport-based asset loader designed to improve page load speed by deferring the loading of images, videos, iframes, and backgrounds. It functions as an intersection observer media loader that triggers resource downloads and script execution only when elements enter the browser viewport. The project also serves as a native lazy loading polyfill, utilizing native browser loading attributes where supported and providing a JavaScript fallback for older environments.
The library distinguishes itself through active bandwidth management, such as aborting the download of media elements that exit the viewport before they finish loading. It supports high-efficiency image formats like WebP and provides mechanisms for loading appropriate image resolutions responsively. Additionally, it handles dynamic content by updating its observers to detect and load new elements added to the document asynchronously.
The system covers a broad range of performance and recovery capabilities, including error handling for network failures and the ability to assign fallback images. It manages various loading states through an event callback system and supports the deferred initialization of complex UI components. Users can customize element selectors and manage multiple independent instances across different containers.