npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

lazyish

v1.1.2

Published

A lightweight, zero-dependency lazy loading micro-library using native browser APIs

Downloads

85

Readme

lazyish

A lightweight, zero-dependency lazy loading micro-library using native browser APIs (IntersectionObserver, MutationObserver, ResizeObserver).

CI npm version License: MIT

Features

  • 🚀 Tiny – under 2 KB minified + gzipped
  • 🔌 Zero dependencies – uses native browser APIs only
  • 📦 ESM / CJS / IIFE – works everywhere
  • 🔀 Two modes – passive (loading="lazy") and active pipelines (data-*)
  • 🖼️ Imagesdata-src, data-srcset, data-sizes="auto"
  • 🎨 Background imagesdata-bg on any element
  • 📺 Iframes – lazy-load <iframe> with data-src
  • 🎬 Videos – lazy-load <video> with data-src, data-poster, and <source> children
  • SPA-friendly – auto-discovers new elements via MutationObserver
  • 📐 Responsive – auto-updates sizes via ResizeObserver
  • 🎯 TypeScript – fully typed

Installation

npm install lazyish

Or via CDN:

<script src="https://unpkg.com/lazyish/dist/lazyish.iife.js"></script>

Quick Start

<!-- Native lazy images & media (also works for <video> and <audio>) -->
<img class="lazyload" src="image.jpg" loading="lazy" alt="passive">
<iframe class="lazyload" src="embed.html" loading="lazy"></iframe>
<video class="lazyload" src="video.mp4" loading="lazy" controls></video>
<audio class="lazyload" src="audio.mp3" loading="lazy" controls></audio>

<!-- Observer-controlled responsive images -->
<img class="lazyload"
     data-src="img-800.jpg"
     data-srcset="img-400.jpg 400w, img-800.jpg 800w"
     data-sizes="auto"
     alt="active">

<!-- Background images -->
<div class="lazyload" data-bg="hero.jpg"></div>

<!-- Iframes -->
<iframe class="lazyload" data-src="https://example.com" title="Lazy iframe"></iframe>

<!-- Videos -->
<video class="lazyload" data-src="video.mp4" data-poster="poster.jpg" controls></video>

<!-- Videos with multiple sources -->
<video class="lazyload" data-poster="poster.jpg" controls>
  <source data-src="video.mp4" type="video/mp4">
  <source data-src="video.webm" type="video/webm">
</video>
import lazyish from 'lazyish';

// Initialize with defaults
lazyish();

// Or with custom options
lazyish({
  selector: '.lazyload',
  rootMargin: '200px',
  classLoaded: 'lazyloaded',
  onLoad: (el) => console.log('Loaded:', el),
});

Modes: Active vs Passive

lazyish supports two ways to work with lazy loading.

Passive mode (native loading="lazy")

Use normal media markup with native lazy loading:

<img class="lazyload" src="image.jpg" loading="lazy" alt="...">

In passive mode, the browser controls fetching. lazyish handles CSS class lifecycle (lazyloaded/lazyerror) and callbacks.

  • Supported elements: <img>, <iframe>, <video>, <audio>
  • Requirements: has src, has loading="lazy", NO data-* attributes.
  • Note: browser controls fetch timing; may vary by element/browser (espcially <video>/<audio>).

Active mode (IntersectionObserver)

Use data-* attributes (data-src, data-bg, etc) and let lazyish unveil via IntersectionObserver.

  • Supported elements: <img>, <iframe>, <video>, any [data-bg]
  • Behavior: custom preload margins, responsive auto-sizing, unveil hooks.

Default mode by element

  • <img>, <audio>: Passive mode by default (src + loading="lazy").
  • <iframe>, <video>: Passive mode for simple embeds, Active mode when using data-src/data-poster or needing observer tuning.
  • Backgrounds (data-bg="..."): Active mode always.

Which should I use?

  • Use passive for most regular images/media.
  • Use active for responsive pipes (data-srcset), fine-grained observer control, backgrounds, and older browser <video>/<iframe> support.

API

lazyish(options?): LazyishInstance

Initializes lazy loading and returns an instance.

Options

| Option | Type | Default | Mode | Description | |--------|------|---------|------|-------------| | selector | string | '.lazyload' | Both | CSS selector for lazy elements | | classLoading | string | 'lazyloading' | Both | Class added while loading | | classLoaded | string | 'lazyloaded' | Both | Class added when loaded | | classError | string | 'lazyerror' | Both | Class added on error | | rootMargin | string | '200px' | Active | IntersectionObserver root margin | | threshold | number\|number[] | 0 | Active | IntersectionObserver threshold | | observeDOM | boolean | true | Both | Auto-discover new elements | | autoSizes | boolean | true | Active | Auto-compute sizes attribute | | backgroundImages | boolean | true | Active | Support data-bg | | onLoad | (el) => void | — | Both | Callback on successful load | | onError | (el) => void | — | Both | Callback on load error | | onBeforeUnveil | (el) => void | — | Active | Callback before unveiling |

Instance Methods

| Method | Description | |--------|-------------| | observe(el) | Manually observe an element | | triggerLoad(el) | Force-load an element immediately | | update() | Re-scan DOM for new elements | | destroy() | Tear down all observers |

Examples

See the examples/ directory:

CSS

Add transitions for smooth loading:

img {
  opacity: 0;
  transition: opacity 0.4s ease;
}
img.lazyloaded {
  opacity: 1;
}
img.lazyerror {
  opacity: 0.3;
}

Browser Support

All modern browsers that support IntersectionObserver (Chrome 51+, Firefox 55+, Safari 12.1+, Edge 15+).

License

MIT © smonist