1.0.0 • Published 5 years ago

script-loader-async v1.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

Async Script Loader

PRs Welcome

This tiny util allows you to dynamically load a script into the global scope.

Usage

Call loadScript with the three required parameters:

  • namespace e.g. if the script is accessible via window.coolUtil the namespace is coolUtil
  • url
  • callback function - this recieves the promise which will either resolve or reject and a cancelSource token if you need to abort the request.
  • window object

Example

// import the util
import loadScript from 'async-script-loader;

// define your callback function
const callbackFn = (response) => {
  // if successful the script will be available in the global scope under the namespace you provided

  // if unsuccessful the error message is returned
}

// do the thing
loadScript('coolUtil', 'https://coolutil.com', window, callbackFn);
  • Backed by tests in Jest
  • Typed with FlowType
  • Linted with ESLint
  • PR's welcome
  • API improvements welcome
1.0.0

5 years ago