@digital-swing/lazy-module
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @digital-swing/lazy-module

Weekly Downloads

1

Version

2.1.0

License

MIT

Unpacked Size

14.7 kB

Total Files

9

Last publish

Collaborators

  • lucasdemea