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

lazy-loadable

v0.1.3

Published

Boilerplate for creating lazy-loadable images.

Readme

Native lazy load boilerplate

  • 🧱 Pollyfill for modern browsers
  • 👵 Gracefully degrades for old browsers
  • 🤖 Future proof markup
  • 🚉 Using the platform

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.

Boilerplate

<img 
    is="lazy-loadable" 
    loading="lazy" 
    lazyload="1" 
    importance="low" 
    srcset="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42gEFAPr/AP///wAI/AL+Sr4t6gAAAABJRU5ErkJggg==" 
    src="https://placekitten.com/400/400" 
    width="400" 
    height="400" 
    alt=""
>
<script type="module">
    import LazyLoadable from 'https://cdn.pika.dev/lazy-loadable';
    customElements.define('lazy-loadable', LazyLoadable, { extends: "img" });
</script>

Attributes breakdown

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.

Safari custom elements pollyfill

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:

<script>
    if(this.customElements)
    try{customElements.define('built-in',document.createElement('p').constructor,{'extends':'p'})}
    catch(s){document.write('<script src="//unpkg.com/@ungap/custom-elements-builtin"><\x2fscript>')}
    else
    document.write('<script src="//unpkg.com/document-register-element"><\x2fscript>');
</script>

Install

If you prefer to bundle the pollyfill yourself or use it with a framework:

npm install lazy-loadable -s
import LazyLoadable from 'lazy-loadable';
customElements.define('lazy-loadable', LazyLoadable, { extends: "img" });

License

Distributed under the MIT license. See LICENSE for details.