2.1.0 ā€¢ Published 5 months ago

@digital-swing/lazy-module v2.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

lazy-module

Typescript Gzip Coverage Badge CI Status

šŸš€ Reduce initial page load time by asynchronously loading modules, only when they are required. šŸš€

šŸ“„ Installation

@digital-swing/lazy-module is available as a npm package.

npm

npm install @digital-swing/lazy-module

yarn

yarn add @digital-swing/lazy-module

Then import it as a esm package in your app :

import  { LazyModule } from '@digital-swing/lazy-module';

šŸ› ļø Usage

Simple

const moduleLoader = new moduleLoader({
  trigger: '.trigger',
  loader: 'my-module',
});

moduleLoader.init()

This will load the my-module module when it enters into view.

With custom parameters

const moduleLoader = new moduleLoader({
  trigger: '.swiper-button-next, .swiper-button-prev',
  loader: () => {
    import('swiper/css/navigation');
    return import('swiper' /* webpackChunkName: "swiper" */);
  },
  callback: (ImportedModule, el) => {
    ImportedModule.Swiper.use(ImportedModule.Navigation);
    el.closest('.swiper').swiper.update();
  },
  on: 'scroll',
  dependsOn: [swiper],
  observerOptions:{
    root: document.querySelector('body'),
    rootMargin: '200px',
    thresholds: 0.0,
    }
});

moduleLoader.init()

šŸ’¬ Changelog

Please see the CHANGELOG for more information about what has changed recently.

šŸ› Testing

npm test

See the full API in the docs.

šŸŒ Contributing

Please see CONTRIBUTING for details.

šŸ”’ Security

If you discover any security related issues, please email lucas@digital-swing.com instead of using the issue tracker.

šŸ‘„ Credits

Lucas Demea

šŸ—’ Roadmap

  • Run callback in a service worker
2.1.0

5 months ago

2.0.3

10 months ago

2.0.2

10 months ago

2.0.5

6 months ago

2.0.0

1 year ago

1.0.2

1 year ago

1.0.0

1 year ago