lazyload is a little bit of JavaScript (826 bytes) that tries to polyfill lazy loading support for <img> elements, <picture> elements, and CSS background images.
If lazy loading is natively supported already, lazyload will know and get out of the way.
https://theoutfit-lazyload.netlify.app/
- Install it:
npm i @theoutfit/lazyload --save - Import it:
import lazyload from '@theoutfit/lazyload' - Call it:
lazyload() - Adjust your code:
- change every
imgelement’ssrcattribute todata-lazy-src - change every
imgelement’ssrcsetattribute todata-lazy-srcset - add a
loading="lazy"attribute to everyimgelement - add a
lazy-bgclass to every element with a background-image - add this rule to your CSS:
.lazy-bg { background-image: none !important; }
- change every
Fadable is available under the MIT license.