From fc21ef5c62d845576a916414468b3a57370a57b2 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 4 Jun 2021 14:39:47 +0200 Subject: Speed up plugins loading --- client/src/root-helpers/utils.ts | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'client/src/root-helpers/utils.ts') diff --git a/client/src/root-helpers/utils.ts b/client/src/root-helpers/utils.ts index 06591b95e..00bd92411 100644 --- a/client/src/root-helpers/utils.ts +++ b/client/src/root-helpers/utils.ts @@ -1,5 +1,3 @@ -import { environment } from '../environments/environment' - function objectToUrlEncoded (obj: any) { const str: string[] = [] for (const key of Object.keys(obj)) { @@ -21,41 +19,6 @@ function copyToClipboard (text: string) { document.body.removeChild(el) } -// Thanks: https://github.com/uupaa/dynamic-import-polyfill -function importModule (path: string) { - return new Promise((resolve, reject) => { - const vector = '$importModule$' + Math.random().toString(32).slice(2) - const script = document.createElement('script') - - const destructor = () => { - delete window[ vector ] - script.onerror = null - script.onload = null - script.remove() - URL.revokeObjectURL(script.src) - script.src = '' - } - - script.defer = true - script.type = 'module' - - script.onerror = () => { - reject(new Error(`Failed to import: ${path}`)) - destructor() - } - script.onload = () => { - resolve(window[ vector ]) - destructor() - } - const absURL = (environment.apiUrl || window.location.origin) + path - const loader = `import * as m from "${absURL}"; window.${vector} = m;` // export Module - const blob = new Blob([ loader ], { type: 'text/javascript' }) - script.src = URL.createObjectURL(blob) - - document.head.appendChild(script) - }) -} - function wait (ms: number) { return new Promise(res => { setTimeout(() => res(), ms) @@ -64,7 +27,6 @@ function wait (ms: number) { export { copyToClipboard, - importModule, objectToUrlEncoded, wait } -- cgit v1.2.3