0.2.0 • Published 1 year ago
@internetarchive/lazy-loader-service v0.2.0
Lazy Loader Service
An ES module to lazy load javascript. Based on the lazy loader from Vaadin Router.
Installation
yarn add @internetarchive/lazy-loader-serviceUsage
import { LazyLoaderService } from '@internetarchive/lazy-loader-service';
const lazyLoaderService = new LazyLoaderService();
await lazyLoaderService.loadScript({ src: 'https://my-server.com/some-service.js' });
// assuming `some-service.js` creates `window.someService`
const response = window.someService.getResponse('foo');
...Advanced Usage
Use an alternate script container instead of document.head (the default).
<div id="script-container"></div>import { LazyLoaderService } from '@internetarchive/lazy-loader-service';
const container = document.querySelector('#script-container');
const lazyLoaderService = new LazyLoaderService(container);Load a javascript module / nomodule
import { LazyLoaderService } from '@internetarchive/lazy-loader-service';
const lazyLoaderService = new LazyLoaderService();
await lazyLoaderService.loadBundle({
module: 'https://my-server.com/some-service-module.js',
nomodule: 'https://my-server.com/some-service-nomodule.js'
});
const response = window.someService.getResponse('foo');
...Add additional attributes to the script tags
import { LazyLoaderService } from '@internetarchive/lazy-loader-service';
const lazyLoaderService = new LazyLoaderService();
await lazyLoaderService.loadScript({
src: 'https://my-server.com/some-service.js',
attributes: [{ key: 'foo', value: 'bar' }]
});
=>
<script src="https://my-server.com/some-service.js" async foo="bar"></script>Development
Prerequisite
yarn installStart Development Server
yarn startTesting
yarn testTesting via browserstack
yarn test:bsLinting
yarn lint0.2.1-alpha.2
1 year ago
0.2.1-alpha.1
3 years ago
0.2.0-alpha.2
4 years ago
0.2.0
4 years ago
0.2.0-alpha.1
4 years ago
0.2.0-alpha.4
4 years ago
0.2.0-alpha.3
4 years ago
0.1.0
6 years ago
0.0.0-alpha.3
6 years ago
0.0.0-alpha.4
6 years ago
0.0.0-alpha.2
6 years ago
0.0.0-alpha.1
6 years ago
0.0.1-alpha.564
6 years ago
0.0.1-alpha.563
6 years ago