load-async-script

1.0.1 • Public • Published

Async Script Loader

A tiny script for loading 3rd party scripts asynchronously such as loading Google Maps or reCaptcha script.

Usage:

// import
import loadAsyncScript from 'load-async-script';


// usage
const scriptPromise = loadAsyncScript( '__SCRIPT_SRC__', { 
    onLoad: scriptOnLoad, 
    onError: scriptOnError 
} );


// script on load callback
function scriptOnLoad() {
    console.log( 'script loaded' )
}

// script error callback
function scriptOnError() {
    console.log( 'script loaded' )
}

// or use promise
scriptPromise.then( () => {
    console.log( 'script loaded' )
}).catch( ( reason ) => {
    console.log( reason )
})

Package Sidebar

Install

npm i load-async-script

Weekly Downloads

0

Version

1.0.1

License

none

Unpacked Size

3.31 kB

Total Files

4

Last publish

Collaborators

  • delowar