unlazy
April 21, 2026 ยท View on GitHub
unlazy
Universal lazy loading library leveraging native browser APIs. Built around the loading="lazy" attribute, with BlurHash / ThumbHash placeholders, a dedicated above-the-fold priority path, and a dev-mode LCP warning so you never ship a lazy-loaded hero image by accident.
Features
- ๐ Native: Utilizes the
loading="lazy"attribute - ๐๏ธ Framework-agnostic: Works with any framework or no framework at all
- ๐ BlurHash & ThumbHash support: SSR & client-side BlurHash and ThumbHash decoding
- โก Core Web Vitals-aware: Eager-priority path for above-the-fold images, dev-mode LCP warning
- ๐ช Sizing: Automatically calculates the
sizesattribute - ๐ SEO-friendly: Detects search engine bots and preloads all images
- ๐
<picture>: Supports multiple image tags - ๐ Auto-initialize: Usable without a build step
Setup
# pnpm
pnpm add -D unlazy
# npm
npm i -D unlazy
Basic Usage
To apply lazy loading to all matching images, import the lazyLoad function and call it without any arguments:
import { lazyLoad } from 'unlazy'
// Processes `img[loading="lazy"]` and `img[loading="eager"][data-src|data-srcset]`
lazyLoad()
For above-the-fold images (your hero / LCP image), use loading="eager". unlazy swaps the real source immediately and applies fetchpriority="high" for you:
<img loading="eager" data-src="hero.jpg" width="1600" height="900" alt="Sunset">
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.
๐ป Development
- Clone this repository
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Run
pnpm run dev:prepare - Start development server using
pnpm run devinside the one of thepackagesdirectories
License
MIT License ยฉ 2023-PRESENT Johann Schopplich
