split
This commit is contained in:
parent
a05c031074
commit
94571943cf
23 changed files with 817 additions and 5563 deletions
22
js/module-loader.js
Normal file
22
js/module-loader.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
const root = window.PixelIslandModules ||= {};
|
||||
const pending = new Map();
|
||||
|
||||
function loadScript(src) {
|
||||
if (pending.has(src)) return pending.get(src);
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script');
|
||||
script.src = src;
|
||||
script.defer = true;
|
||||
script.onload = () => resolve(script);
|
||||
script.onerror = () => reject(new Error(`Could not load ${src}`));
|
||||
document.head.appendChild(script);
|
||||
});
|
||||
pending.set(src, promise);
|
||||
return promise;
|
||||
}
|
||||
|
||||
root.ModuleLoader = { loadScript };
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue