cdn-promise

1.0.1 • Public • Published

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);
});

Readme

Keywords

none

Package Sidebar

Install

npm i cdn-promise

Weekly Downloads

242

Version

1.0.1

License

ISC

Last publish

Collaborators

  • tomrees