Load a script from the given URL if it (window["attribute"]) has not already been loaded.
window["attribute"]
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); }); Copy
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. Copy
xyz is loaded.
The name of the window attribute to check (e.g. jQuery, axios, etc.).
jQuery
axios
The URL of the script to load.
A Promise that resolves when the script has been loaded.
Load a script from the given URL if it (
window["attribute"]) has not already been loaded.Usage:
Output: