
lazysizes
A lightweight JavaScript lazy loader for images, responsive images, and iframes that needs little or no config
- Stars
- 17.7k
- Forks
- 1.7k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 2.6 years ago
- Type
- Library
No commits in over a year — check for forks or alternatives before adopting.
What it is
lazysizes is a small JavaScript script that delays loading images and iframes until they are about to appear on screen, so pages load faster. It works with ordinary HTML: you add a class and a data attribute, and it handles the rest. It also helps with responsive images by calculating the sizes attribute automatically and supporting picture and srcset markup.
- Add lazy loading to a photo gallery by adding the lazyload class and a data-src attribute to each image
- Serve responsive images with data-sizes="auto" and data-srcset so the browser picks an appropriately sized file
- Lazy load embedded videos by setting data-src on an iframe with the lazyload class
- Delay loading of images inside carousels or hidden menus that appear through user interaction
Great for
- Websites with many images, such as photo galleries or long article pages
- Developers who want lazy loading without writing much JavaScript configuration
- Sites that show content in carousels, sliders, or infinite scroll and need visibility changes detected
- Teams building responsive image markup who want automatic sizes calculation
Not ideal for
- Projects that need full cross-browser responsive image support without polyfills: the README says a polyfill such as picturefill or one of its plugins is needed for full support
- Pages where images must have an exact, pre-known width, because automatic sizes depends on the display width being calculable before loading
- Users looking for a no-code website builder plugin: this is a script that web developers include in their pages
How to get it
- 1
Install with a package manager
Install via npm
npm install lazysizes --saveInstall via bower
bower install lazysizes --save - 2
Run it
- Install lazysizes with npm, or download lazysizes.min.js from the project site
- Include the script in your page with a script tag that has the async attribute, or import it in your JavaScript
- Add the class lazyload to an img or iframe and replace src with data-src
- Open the page in a browser and scroll to confirm images load as they come into view
- 3
Get the most out of it
- Use data-sizes="auto" together with data-srcset that uses width descriptors so the browser can choose the best image
- Apply the CSS rule img[data-sizes="auto"] { display: block; width: 100%; } to help automatic sizes calculation
- Use the parent-fit plugin when images must fit a container, including use of object-fit
- Add the attrchange or re-initialization extension when integrating with frameworks that change the DOM after load
- Use the respimg or rias plugins if you need responsive image fallback support in older browsers
Downloads
Strengths
- Detects images that become visible through scrolling, CSS hover effects, or JavaScript, without manual setup, according to the README
- Needs no JavaScript configuration for basic use, as the README describes markup-based usage
- MIT licensed and has a long track record, with about 17.7k GitHub stars
Trade-offs
- Full responsive image support across all browsers requires an additional polyfill, per the README
- Automatic sizes only works when images have a calculable display width, which may need extra CSS such as display block and width 100%
- The latest push shown is from April 2024, so recent maintenance activity may be limited
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| lazysizes (this) | 17.7k | Library | beginner | 2.6 years ago | Websites with many images, such as photo galleries or long article pages |
| fiber | 40.2k | Library | intermediate | 4 days ago | Go developers building REST APIs or web backends |
| fastify | 37.3k | Library | beginner | 4 days ago | Node.js developers building JSON APIs or backend services |
| solid | 36.2k | Library | intermediate | 4 days ago | Developers who want fine-grained control over what re-renders in a web UI |
| react-virtualized | 27.1k | Library | intermediate | 5 days ago | React developers who need to display long lists of items |
| million | 17.7k | Library | intermediate | 6 months ago | React developers whose apps have many elements that update often |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.