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

lazier-js

v0.2.0

Published

Little handy lazy loading images library

Downloads

7

Readme

Known Vulnerabilities

Lazier.js

A little handy library for lazy loading the images of your Page:

It's inspired by the ideas that @JMPerez posted here. In order to work in all major browsers it avoids the CSS filters and uses the HTML5 canvas approach that Medium uses.

It uses a modified and lighter version of Mario Klingemann SuperFastBlur algorithm, modified in order to work with canvas objects and not unique id's.

What does Lazier.js?

In order to speed up the performance of your web page you can lazy load the images of it. That means to load the images when the DOM of your page is already loaded. Lazier.js does this for you!

Oh, and doing it the same way as Medium does it handles it pretty :sparkles: beautifully :sparkles: :wink:

How to use it

Get both lazier.min.js and lazier.min.css. You can download it from github or use npm to get the updated version.

npm install lazier-js

You need to link the minified css file at the header of your page:

<head>
      <link rel="stylesheet" type="text/css" href="lazier.min.css">
</head>

Modify the structure of your HTML file: Lazier.js uses the same HTML structure as Medium you need to replace the images that you want to lazy load by the following block:

<div class="lazierContainer">
      <img class="lazierLowFy" data-src="Test/test_mini_size.jpg">
      <canvas class="lazierCanvas"></canvas>
      <img class="lazierRender" data-src="Test/test2_mini_size.jpg">
      <noscript class="lazierFall">&lt;img class="lazierNoScript" src="big.jpg"&gt;</noscript>
</div>

LowFi Image:

<img class="lazierLowFy" data-src="mini.jpg">

Define as data-src the low fidelity image that you want to use. We have tested it with very small images, with a heavy compression: (25px widht, 20% quality).

HighFi Image:

<img class="lazierRender" data-src="high.jpg">

Define as data-src the the high fidelity image that you want to load.

FallBack Image:

<noscript class="lazierFall">&lt;img class="lazierNoScript" src="high.jpg"&gt;</noscript>

Define here the fallback image that is going to be loaded if the browser doesn't have JavaScript support. (WIP)

Load the minified JavaScript:

<script src="lazier.min.js"></script>

Load the script at your Page and it's done! :star:

Example

<head>
  <link rel="stylesheet" type="text/css" href="lazier.min.css">
</head>
<div style="width: 240px; height: 360px; display: inline-block;">
    <div class="lazierContainer">
        <img class="lazierLowFy" data-src="Test/test_mini_size.jpg">
        <canvas class="lazierCanvas" id='lc'></canvas>
        <img class="lazierRender" data-src="Test/test_medium_size.jpg">
        <noscript class="lazierFall">&lt;img class="lazierNoScript" src="Test/test_medium_size.jpg"&gt;</noscript>
    </div>
</div>

<div style="width: 240px; height: 360px; display: inline-block;">
    <div class="lazierContainer">
        <img class="lazierLowFy" data-src="Test/test2_mini_size.jpg">
        <canvas class="lazierCanvas" id='lc'></canvas>
        <img class="lazierRender" data-src="Test/test2_medium_size.jpg">
        <noscript class="lazierFall">&lt;img class="lazierNoScript" src="Test/test_medium_size.jpg"&gt;</noscript>
    </div>
</div>

<div style="width: 240px; height: 360px; display: inline-block;">
    <div class="lazierContainer">
        <img class="lazierLowFy" data-src="Test/test3_mini_size.jpg">
        <canvas class="lazierCanvas" id='lc'></canvas>
        <img class="lazierRender" data-src="Test/test3_medium_size.jpg">
        <noscript class="lazierFall">&lt;img class="lazierNoScript" src="Test/test_medium_size.jpg"&gt;</noscript>
    </div>
</div>

<div style="width: 240px; height: 360px; display: inline-block;">
    <div class="lazierContainer">
        <img class="lazierLowFy" data-src="Test/test4_mini_size.jpg">
        <canvas class="lazierCanvas"></canvas>
        <img class="lazierRender" data-src="Test/test4_medium_size.jpg">
        <noscript class="lazierFall">&lt;img class="lazierNoScript" src="Test/test_medium_size.jpg"&gt;</noscript>
    </div>
</div>

<script src="lazier.min.js"></script>