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

blazyloader

v0.1.7

Published

Lazy load and unload media

Downloads

4

Readme

BlazyLoader 🔥

Why another lazy loader? Well, I really needed a lazy unloader, and a callback system to allow for slick animations when media has finished loading.

So here we are.

Built on the IntersectionObserver API, its fast and tiny, with no costly getBoundingClientRect usage. Zero dependencies.

Usage

yarn add blazyloader

And in your javascript:

import BlazyLoader from 'blazyloader'

// Create a new instance, all defaults shown below.
// Pass in your own values for each parameter to customize the instance's behavior
let blazy = new BlazyLoader( {
    // Is not limited to "data-attributes", can be generic attributes as well
    // <img blazy-src="http://yoururl.com/image.png">
    tag: 'blazy-src',
    
    // Multiplier of the viewport, that is the "view area"
    // Default is 2.0, which means if the viewport is 800px tall, the view area is double that,
    // and so extends 400px above and 400px below.
    view_scale: 2.0,
    
    // Set to true if you want media to be unloaded when after it exits the viewport
    // It will seamlessly reload as soon as it re-enters the view area,
    // but will free up resources while not needed. Reloading should hit the cache.
    // HTML5 Video elements on iOS webkit will not use the cache on re-load... 
    // I should add in my work around for that into this library...
    unload: false,

    // Set this to the DOM node that both has overflow scroll, and contains all assets you
    // want to lazy load+unload
    container: document.body,
    
    // If you want to bypass blazyloader and dump all blazy-src to src on instantiation
    // Useful for SEO & crawling bots
    bots: false,        
    
    // If you are using this in node.js, ie with jsdom, the `document` global is undefined
    // Pass in the virtual document, with jsdom that would be "new JSDOM().window.document"
    document: undefined 
} )

// Listen to events
blazy.on( 'blazy:set', ( node ) => {
    console.log( 'Set src attribute', node.getAttribute( 'blazy-src' ) )
} )

blazy.on( 'blazy:loaded', ( node ) => {
    console.log( 'Finished loading', node.getAttribute( 'blazy-src' ) )
} )

blazy.on( 'blazy:unset', ( node ) => {
    console.log( 'unload', node.getAttribute( 'blazy-src' ) )
} )

// Later, if you have changed the DOM elements within your container:
blazy.sync_nodes()

And in your html or other templates:

<img blazy-src="{url}">

<iframe blazy-src="{url}" frameborder="0" allow="autoplay; fullscreen;"></iframe>

<div blazy-src="{ media.uri }"> Background Image </div>

<video blazy-src="{ url }">
    <source type="video/mp4"/>
</video>