gitwtfhub

wtf is lozad.js?

apoorvsaxena/lozad.js — explained in plain English

Analysis updated 2026-06-24

7,498JavaScriptAudience · developerComplexity · 1/5LicenseSetup · easy

TL;DR

A tiny, zero-dependency JavaScript library that uses the browser's built-in Intersection Observer to lazy-load images, videos, and iframes only when they scroll into view.

Mindmap

mindmap
  root((lozad.js))
    What it does
      Delays loading off-screen content
      Speeds up initial page load
      Saves user bandwidth
    How it works
      Intersection Observer API
      Data attribute for real URL
      CSS class to mark elements
    Supported elements
      Images and responsive images
      Videos and audio
      Iframes
    Features
      Dynamic element support
      Custom threshold settings
      Background image support
    Audience
      Web developers
      Frontend engineers

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Speed up a photo gallery page by lazy-loading hundreds of images so only visible ones download on arrival.

REASON 2

Reduce bandwidth costs on a video platform by delaying iframe embeds until the user scrolls near them.

REASON 3

Add lazy-loaded background images to a marketing landing page without any extra dependencies.

REASON 4

Improve Core Web Vitals scores on an e-commerce product listing by deferring off-screen product images.

What's in the stack?

JavaScript

How it stacks up

apoorvsaxena/lozad.jsecomfe/echarts-for-weixinblasten/turn.js
Stars7,4987,4987,468
LanguageJavaScriptJavaScriptJavaScript
Setup difficultyeasymoderateeasy
Complexity1/53/52/5
Audiencedeveloperdeveloperdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

No dependencies, add a class to elements, a data-src attribute, and two lines of JavaScript, works immediately.

Open source under a permissive license, use freely in any project including commercial ones.

Wtf does this do

Lozad.js is a small JavaScript library that delays loading images, videos, iframes, and other page elements until they are about to appear on the screen. This technique is called lazy loading, and it speeds up a webpage by avoiding the download of content the visitor has not yet scrolled to. On a long page with many images, this can significantly reduce initial load time and save bandwidth. Most older lazy loading libraries work by listening to the scroll event and repeatedly checking whether each element is close to the visible area. This approach has a performance cost because it forces the browser to measure the position of every tracked element on each scroll event, which can make the page feel sluggish. Lozad.js takes a different approach: it uses the browser's Intersection Observer API, which was designed specifically for this purpose. The browser does the work of noticing when an element enters the viewport, and Lozad.js responds to that notification instead of polling constantly. Using the library is straightforward. You add a class to any element you want to lazy load and store the real URL in a data attribute instead of the normal source attribute. Then you create a Lozad observer with a couple of lines of JavaScript and call its observe method. From that point on, elements are loaded automatically as the user scrolls toward them. The library supports images, responsive images with multiple size variants, iframes, videos, audio elements, background images, and multiple background images on a single element. It also works with elements added to the page dynamically after the initial load, and it can be customized with options for how close to the viewport an element needs to be before loading begins. Lozad.js has no dependencies, weighs about one kilobyte compressed, and is used in production by companies including Tesla, Binance, and Verizon. It is free and open source.

Yoink these prompts

Prompt 1
Show me how to set up lozad.js on a webpage so that all images below the fold are lazy-loaded as the user scrolls.
Prompt 2
How do I use lozad.js to lazy-load responsive images with multiple srcset sizes?
Prompt 3
Write the minimal HTML and JavaScript needed to lazy-load an iframe embed using lozad.js.
Prompt 4
How can I configure lozad.js to start loading images when they are 200 pixels away from the viewport edge?
Prompt 5
Show me how to make lozad.js observe new images added to the page dynamically via JavaScript.

Frequently asked questions

wtf is lozad.js?

A tiny, zero-dependency JavaScript library that uses the browser's built-in Intersection Observer to lazy-load images, videos, and iframes only when they scroll into view.

What language is lozad.js written in?

Mainly JavaScript. The stack also includes JavaScript.

What license does lozad.js use?

Open source under a permissive license, use freely in any project including commercial ones.

How hard is lozad.js to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is lozad.js for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.