Function loadScriptIfUndefined

  • Load a script from the given URL if it (window['attribute']) has not already been loaded.


    loadScriptIfUndefined('xyz', '')
    .then(() => {
    console.log('xyz is loaded.');
    .catch(err => {
    console.log('Failed to load xyz.', err);


    xyz is loaded.


    • windowAttribute: string

      The name of the window attribute to check (e.g. jQuery, axios, etc.).

    • url: string

      The URL of the script to load.

    Returns LoadScriptReturns

    A Promise that resolves when the script has been loaded.