script-loader-async
v1.0.0
Published
Async script loader
Downloads
3
Readme
Async Script Loader
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 viawindow.coolUtil
the namespace iscoolUtil
url
callback
function - this recieves the promise which will either resolve or reject and acancelSource
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);