cdn-promise
v1.0.1
Published
Simple library waits for injected <script> or <style> tag to load resources from a CDN.
Downloads
592
Readme
CDN-PROMISE
Simple library waits for injected <script>
or <style>
tag to load resources from a CDN.
Useful for WebPack apps where a single, embeddable lib.js
or module.js
will bootstrap itself. Very useful for embedding a dynamic widget into an existing page.
Install
npm install --save cdn-promise
Usage
Example in a WebPack app using JQuery and Leaflet.
import documentReady from 'document-ready-promise';
import cdnPromise from 'cdn-promise';
Promise.all([
cdnPromise('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.2/leaflet.css'),
cdnPromise('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js', 'jQuery'),
cdnPromise('https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.2/leaflet.js', 'L'),
documentReady(),
])
.then(() => {
// eslint-disable-next-line global-require
require('./src/index');
})
.catch((err) => {
console.error(err);
});