aFarkas /lazysizes
High performance and SEO friendly lazy loader for images (responsive and normal), iframes and more, that detects any visibility changes triggered through user interaction, CSS or JavaScript without configuration.
★ 17,705⑂ 1,685👁 268⑃ 140● 824▤ 95
+0
Daily
17,705
stars
1,685
forks
268
watchers
140
prs
824
issues
95
releases
README
lazysizes
lazysizes is a fast (jank-free), SEO-friendly and self-initializing lazyloader for images (including responsive images picture/srcset), iframes, scripts/widgets and much more. It also prioritizes resources by differentiating between crucial in view and near view elements to make perceived performance even faster.
It may become also your number one tool to integrate responsive images. It can automatically calculate the sizes attribute for your responsive images, it allows you to share media queries for your media attributes with your CSS, helping to separate layout (CSS) from content/structure (HTML) and it makes integrating responsive images into any environment really simple. It also includes a set of optional plugins to further extend its functionality.
How to
1. Download the lazysizes.min.js script and include lazysizes in your webpage. (Or install via npm: npm install lazysizes --save or bower bower install lazysizes --save)
html
Or:
js
import 'lazysizes';
// import a plugin
import 'lazysizes/plugins/parent-fit/ls.parent-fit';
// Note: Never import/require the .min.js files from the npm package.
Note: For more information see here.
2. lazysizes does not need any JS configuration: Add the class "lazyload" to your images/iframes in conjunction with a data-src and/or data-srcset attribute. Optionally you can also add a src attribute with a low quality image:
html
html
html
Demo with code examples
Can be seen here
Responsive image support (picture and/or srcset)
Lazysizes is built upon the Responsive image standard and extends it with additional functionality. For full cross browser responsive image support you must use either a full polyfill like picturefill or use the extreme lightweight partial respimg polyfill plugin or the responsive image on demand plugin. Alternatively, you can simply define a fallback src via the data-src attribute. If you want to learn more about the responsive image syntax read "The anatomy of responsive images".
What makes lazysizes so awesome:
lazysizes is different than other lazy image loaders.
1. Detects any visibility changes on current and future lazyload elements in any web environment automatically: The script works as an universal, self-initializing, self-configuring and self-destroying component and detects any changes to the visibility of any current and future image/iframe elements automatically no matter whether it becomes visible through a user scroll, a CSS animation triggered through :hover or through any kind of JS behavior (carousel, slider, infinite scroll, masonry, isotope/filtering/sorting, AJAX, SPAs...). It also works automatically in conjunction with any kind of JS-/CSS-/Frontend-Framework (jQuery mobile, Bootstrap, Backbone, Angular, React, Ember (see also the attrchange/re-initialization extension)).
2. Future-proof: It directly includes standard responsive image support (picTop issues
#520TypeError: Illegal invocation at HTMLDocument.document.createEvent only on iOS Safari mobile46 comments · 2018-07-23#697Lazy loading autoplay videos29 comments · 2019-09-04#263Use IntersectionObserver27 comments · 2016-05-01#202Support for BGP & FLIF17 comments · 2015-12-03#216Images not appearing; only appearing on resize in IE11 comments · 2016-01-13#458How to expand image's container to prevent all images appearing in viewport on page load?10 comments · 2018-01-04#254Cloudflare rocket load + lazysizes + ajax content10 comments · 2016-04-04#205Method to trigger a lazysizes initiation?10 comments · 2015-12-07
Discussions
#1006Bug for FF browser0 comments · 2025-10-07#998The best solution for everything! ... except SEO.1 comments · 2024-06-19#986Displayed non image0 comments · 2023-02-24#985Re-lazyload images when list of images changes without reload0 comments · 2023-02-10#975Can you confirm this?1 comments · 2022-11-20#963I'm a bit unclear as to what the widths achieve in data-srcset0 comments · 2022-07-12#955Using internal API without loading the image1 comments · 2022-05-17#952Lazy Loading Duplicate Images0 comments · 2022-04-27
Latest release
5.3.1 5.3.1 2021-03-275.3.1