mazey
    Preparing search index...

    Function loadScriptIfUndefined

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

      Usage:

      import { loadScriptIfUndefined } from "mazey";

      loadScriptIfUndefined("xyz", "https://example.com/lib/xyz.min.js")
      .then(() => {
      console.log("xyz is loaded.");
      })
      .catch(err => {
      console.log("Failed to load xyz.", err);
      });

      Output:

      xyz is loaded.
      

      Parameters

      • 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.