Home Manual Reference Source
import ScriptLoaderSingleton from 'ievv_jsbase/lib/dom/ScriptLoaderSingleton'
public class | source

ScriptLoaderSingleton

Asyncronous script loader.

Example:

const scriptLoader = new ScriptLoaderSingleton();
scriptLoader.load('//example.com/myscript.js').then((script) => {
  console.log(`The ${script.src} script was loaded`);
});

Constructor Summary

Public Constructor
public

Get an instance of the singleton.

Method Summary

Public Methods
public

Load a script.

Public Constructors

public constructor source

Get an instance of the singleton.

The first time this is called, we create a new instance. For all subsequent calls, we return the instance that was created on the first call.

Public Methods

public load(src: string): Promise source

Load a script.

Params:

NameTypeAttributeDescription
src string

The source URL of the script.

Return:

Promise

A Promise that resolves when the script is loaded. We do not handle errors (not possible with the insert script tag approach), so this promise will never be rejected.