mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-09-15 15:15:29 +02:00
perf: load document libraries only when needed
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
const pending = new Map();
|
||||
// Generated from the completed library bundles, so deployments invalidate caches.
|
||||
const assets = __LAZY_ASSETS__;
|
||||
export function loadLibrary(name) {
|
||||
if (!pending.has(name)) {
|
||||
const script = document.createElement("script");
|
||||
script.src = assets[name];
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
script.onload = resolve;
|
||||
script.onerror = () => {
|
||||
pending.delete(name);
|
||||
script.remove();
|
||||
reject(new Error(`Unable to load ${name}. Please retry.`));
|
||||
};
|
||||
});
|
||||
pending.set(name, promise);
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
return pending.get(name);
|
||||
}
|
||||
export async function loadEditor() {
|
||||
await loadLibrary("editor");
|
||||
ace.config.set("basePath", "/script/external/ace/");
|
||||
}
|
||||
Reference in New Issue
Block a user