Gathering detailed insights and metrics for lazy-loadable
Gathering detailed insights and metrics for lazy-loadable
Gathering detailed insights and metrics for lazy-loadable
Gathering detailed insights and metrics for lazy-loadable
npm install lazy-loadable
Typescript
Module System
Node Version
NPM Version
66.1
Supply Chain
92.7
Quality
75.1
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,411
Last Day
1
Last Week
4
Last Month
29
Last Year
168
MIT License
17 Stars
44 Commits
3 Watchers
1 Branches
5 Contributors
Updated on Nov 25, 2019
Minified
Minified + Gzipped
Latest Version
0.1.3
Package Id
lazy-loadable@0.1.3
Unpacked Size
6.66 kB
Size
3.40 kB
File Count
4
NPM Version
6.4.1
Node Version
10.13.0
Cumulative downloads
Total Downloads
Last Day
-66.7%
1
Compared to previous day
Last Week
-76.5%
4
Compared to previous week
Last Month
45%
29
Compared to previous month
Last Year
-38.2%
168
Compared to previous year
No dependencies detected.
The whole idea is to create a copy-past boilerplate that works today. If by a miracle all browser vendors agree to ship "native lazy load", you would only have to change one place.
1<img 2 is="lazy-loadable" 3 loading="lazy" 4 lazyload="1" 5 importance="low" 6 srcset="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42gEFAPr/AP///wAI/AL+Sr4t6gAAAABJRU5ErkJggg==" 7 src="https://placekitten.com/400/400" 8 width="400" 9 height="400" 10 alt="" 11> 12<script type="module"> 13 import LazyLoadable from 'https://cdn.pika.dev/lazy-loadable'; 14 customElements.define('lazy-loadable', LazyLoadable, { extends: "img" }); 15</script>
is="lazy-loadable"
Apply the lazy-loadable custom element pollyfill behaviour to your image tag. Usually people loop over all images on a page (querySelectorAll('img.lazy').forEach), to decide if it should lazy load, it can be very slow, you also have to wait until the DOM is ready or put your script at end of body, it would not work if a image appears in document after the document have loaded, like in infinity scrolling or lazy rendering. Using custom elements the browser handles all of it for you.
loading="lazy"
The native way to tell the browser to delay the image loading, until it's in the screen. Only Google Chrome have shipped it yet.
lazyload="1"
It seems Microsoft implemented on IE 11 and Edge 12 a unofficial attribute called "lazyload". But it does not work the same way as "loading=lazy", it only tell the browser to decrese the loading priority of the resource. Actually it's pretty similar to what "importance=low" does.
importance="low"
This is a spec proposal to enable developers to signal the priority of each resource they need to download. In case a browser vendor never implement the "native lazy load", but for any reason ships the priority hints support, we would at least download the image without high priority.
srcset Since there is no ways yet to know if the browser have native support before images starts loading we need to set a placeholder image.
Our placeholder is the one responsible for the magic. I've chosen to use srcset as placeholder instead of a infamous "data-src". By placing the placeholder on "srcattr", we can hold the "src" loading, until we are sure if the browser handles lazy by default. In future if all browsers support native lazy-load, all you would have to do is remove this attribute from your html.
The great advantage of using "srcattr" instead of "data-src" is that when you remove the placeholder, browsers already knows what to do, respecting the standard fallback src, picture source, media attributes and pixel density.
width & height Explicitally declare the image size to avoid page jumps.
Apple have chosen to not ship a complete implementation of custom elements V1, in order for it to work in Safari you may have to use the ungap pollyfill before your scripts:
1<script> 2 if(this.customElements) 3 try{customElements.define('built-in',document.createElement('p').constructor,{'extends':'p'})} 4 catch(s){document.write('<script src="//unpkg.com/@ungap/custom-elements-builtin"><\x2fscript>')} 5 else 6 document.write('<script src="//unpkg.com/document-register-element"><\x2fscript>'); 7</script>
If you prefer to bundle the pollyfill yourself or use it with a framework:
1npm install lazy-loadable -s
1import LazyLoadable from 'lazy-loadable'; 2customElements.define('lazy-loadable', LazyLoadable, { extends: "img" });
Distributed under the MIT license. See LICENSE for details.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-10
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More