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 🙏

© 2024 – Pkg Stats / Ryan Hefner

lazzy

v3.0.1

Published

Modern and lightweight lazy loading library

Downloads

1,816

Readme

lazzy

  • No dependencies
  • No unnecessary requests
  • Handles responsive images
  • SEO friendly (doesn't remove the src attribute)

Installation

npm i lazzy

Require as a module:

const lazzy = require('lazzy');

In browser:

<script src="dist/lazzy.min.js"></script>

Usage

To use lazzy just add the .lazzy class and the following srcset to your images:

<img class="lazzy"
    src="images/1200.png"
    srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
    alt="" />

To use lazzy with responsive images, list your images in the data-srcset attribute:

<img class="lazzy"
    src="images/1200.png"
    data-srcset="images/400.png 400w, images/600.png 600w, images/1000.png 1000w"
    srcset="data:image/gif;base64,R0lGODlhAQABAIAAAP///////yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
    alt="" />

Options

Custom selector

You don't need to init lazzy. But if you want to use a custom selector, run the following code:

lazzy.run('.my-lazzy-selector');

or specify multiple selectors:

lazzy.run(['.my-lazzy-page img', '.my-lazzy-selector']);

Preload images

With Lazzy, you can easily preload images by setting the preload rule:

lazzy.run({
    selector: ['.my-lazzy-page img', '.my-lazzy-selector'],
    preload: '100px' // Load images 100px earlier
});

or

lazzy.run({
    preload: 100 // Load images 100px earlier
});

or, set the preload as a percentage of the current viewport height:

lazzy.run({
    preload: '20%' // Load images 20% earlier
});

Retina & 4k support

Request image resolution depending on Pixel density (PPI)

lazzy.run({
    pixelDensity: true // false, by default
});

A concept

A lightweight lib that doesn't break your HTML by removing the src.

To avoid unnecessary requests lazzy uses a base64-encoded 1x1px image in the srcset attribute as a placeholder - data:image/gif;base64,R0lGOD...

Note that you can use your own placeholder images. For example, blurred previews when downloading better quality images.

Browser support

The lazy loading works in browsers supporting the srcset attribute, that's about 90%.

Unsupported browsers will load the image in the src attribute. That's the image search engines and social networks will find, so it's better to make it high resolution.

DOM changes

The library will listen for DOM changes and you can also trigger visible images loading by calling: lazzy.run().

License

Free to use under the MIT license.