UNPKG

load-scripts

Version:

Dynamic scripts loading for modern browsers.

2 lines 708 B
/*! load-scripts v2.0.0 | (c) 2018-present Chen Fengyuan | MIT */ !function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e="undefined"!=typeof globalThis?globalThis:e||self).loadScripts=o()}(this,(function(){"use strict";return function(...e){return Promise.all(e.map((e=>new Promise(((o,n)=>{const t=document.head||document.body||document.documentElement;if(t.querySelector(`script[src*="${e}"]`))return void o(e);const r=document.createElement("script"),d=()=>{r.onerror=null,r.onload=null};r.onerror=()=>{d(),n(new Error(`Failed to load script: ${e}`))},r.onload=()=>{d(),o(e)},r.async=!0,r.src=e,t.appendChild(r)})))))}}));