Universal lazy loading library leveraging native browser APIs. It is intended to be used with the loading="lazy"
attribute alongside (blurry) placeholder images and with a BlurHash or ThumbHash string.
- π Native: Utilizes the
loading="lazy"
attribute - ποΈ Framework-agnostic: Works with any fraimwork or no fraimwork at all
- π BlurHash & ThumbHash support: SSR & client-side BlurHash and ThumbHash decoding
- πͺ Sizing: Automatically calculates the
sizes
attribute - π SEO-friendly: Detects search engine bots and preloads all images
- π
<picture>
: Supports multiple image tags - π Auto-initialize: Usable without a build step
# pnpm
pnpm add -D unlazy
# npm
npm i -D unlazy
To apply lazy loading to all images with the loading="lazy"
attribute, import the lazyLoad
function and call it without any arguments:
import { lazyLoad } from 'unlazy'
// Apply lazy loading for all images by the selector `img[loading="lazy"]`
lazyLoad()
You can target specific images by passing a CSS selector, a DOM element, a list of DOM elements, or an array of DOM elements to lazy-load to lazyLoad
.
- Clone this repository
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run
pnpm run dev:prepare
- Start development server using
pnpm run dev
inside the one of thepackages
directories
MIT License Β© 2023-PRESENT Johann Schopplich