2.1.0 ā¢ Published 5 months ago
@digital-swing/lazy-module v2.1.0
lazy-module
š 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
š 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
š Roadmap
- Run callback in a service worker