From 9109ab8407c29dc8c16078e59f55ea4e76a0a987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Kr=C3=B6g?= Date: Sat, 13 Aug 2022 15:00:04 +0200 Subject: [PATCH] Only load lzstring script when clicking Edit --- examples/resources/common.js | 15 +++++++++++++++ examples/templates/example.html | 1 - 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/resources/common.js b/examples/resources/common.js index 8f61696ca5..7454fb34b3 100644 --- a/examples/resources/common.js +++ b/examples/resources/common.js @@ -2,6 +2,20 @@ "use strict" /* global LZString */ + let lzStringPromise; + function loadLzString() { + if (!lzStringPromise) { + lzStringPromise = new Promise(function (resolve, reject) { + const script = document.createElement('script') + script.src = 'https://unpkg.com/lz-string@1.4.4/libs/lz-string.min.js'; + document.head.append(script); + script.addEventListener('load', resolve); + script.addEventListener('error', reject); + }); + } + return lzStringPromise; + } + function compress(json) { return LZString.compressToBase64(JSON.stringify(json)) .replace(/\+/g, '-') @@ -56,6 +70,7 @@ const promises = localResources.map(function (resource) { return fetchResource(resource); }); + promises.push(loadLzString()); Promise.all(promises).then( function (results) { diff --git a/examples/templates/example.html b/examples/templates/example.html index 651308ab53..e26a342510 100644 --- a/examples/templates/example.html +++ b/examples/templates/example.html @@ -3,7 +3,6 @@ -