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

@pernod-ricard-global-cms/cbllazyloader

v2.1.1

Published

Lazyloader utility

Downloads

1,800

Readme

CblLazyloader

The cblLazyloader is a tool that uses intersection observer to dynamically load css and javascript.

How to get started

Install cblLazyloader with NPM.

npm i @pernod-ricard-global-cms/cbllazyloader

Import the module in your js file. The module uses a default export so you can reference with whatever name you like in your file.

import lazyloader from '@pernod-ricard-global-cms/cbllazyloader';

However, we have not yet given it anything to look for. To do this we need to pass it an array of objects called each of which needs at least one key value pair of the form:

[{'assetKey' : <string>}]

For the lazyloader to find anything on the screen that it can load assets for, the html element needs to have the assetkey added as a data-attribute. eg:

<section class="some-element" data-assetkey="<string>">

The string in the data attribute must match the string value of the object we are going to pass to the lazyloader. The assets that the lazyloader will look for will also need to have the same name as the assetkey. Eg. <string>.js or <string>.scss>

Finally we can send the names to the lazyloader by updating it's options object. Eg.

lazyloader.options.assetArray = [{'assetKey' : <string>}];

The lazyloader will be looking for js files in a specific folder which it will run when the corresponding elements have become visible in the browser. The folder path is prefixed with an alias which is 'Assets'. This alias needs to be created in your bundler and the folder accessible via this alias. You can add additional file path structure to the alias by specifying the extra structure in the filepath option. eg:

lazyloader.options.filepath = 'js/blocks/';

Which will give you a combined path of:

'Assets/js/blocks/'

Lastly summon an instance of the lazyloader in your js with the lazyloaderInit() method.

lazyloader.lazyloaderInit();

The lazyloader should now be up and running and looking for things to lazyload!

For some helpful messages and some indication that the module is working, try changing the debugLogMessages option to true in your js file. Just make sure to set the option before invoking the lazyloaderInit() method.

lazyloader.options.debugLogMessages = true;
lazyloader.lazyloaderInit();

Options, overrides and defaults

The current default settings for the lazyloader are as follows.

const options = {
    rootMargin: '0% 0% 0%',
    threshold: 0,
    debugLogMessages: false,
    lazyBlocksToSearchFor: [],
    lazyBlocksFound: [],
    assetArray: [],
    assetMap: {},
    ignoreCss: false,
    lazy: true,
    filePath: 'js/components/blocks/',
};

note: the filepath is currently prefixed with the webpack alias 'Assets'. You would need to be able set this alias in your bundler for the lazyloader to work. The filePath is itself optional so you can use just the alias.