From b91324992dee1a26e5ab50558ac62e96ac28f30d Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 29 Aug 2017 17:12:46 +0300 Subject: [PATCH] skip already queued in onDOMscripted --- js/dom.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/js/dom.js b/js/dom.js index b5c2bc3c..091f58be 100644 --- a/js/dom.js +++ b/js/dom.js @@ -68,14 +68,15 @@ function onDOMready() { function onDOMscripted(scripts) { + const queue = onDOMscripted.queue = onDOMscripted.queue || []; if (scripts) { return new Promise(resolve => { addResolver(resolve); - onDOMscripted.scriptQueue = scripts; + queue.push(...scripts.filter(el => !queue.includes(el))); loadNextScript(); }); } - if (onDOMscripted.scriptQueue) { + if (queue.length) { return new Promise(resolve => addResolver(resolve)); } if (document.readyState !== 'loading') { @@ -88,9 +89,9 @@ function onDOMscripted(scripts) { return onDOMready().then(onDOMscripted); function loadNextScript() { - const next = onDOMscripted.scriptQueue.shift(); - if (!next) { - onDOMscripted.scriptQueue = null; + const empty = !queue.length; + const next = !empty && queue.shift(); + if (empty) { onDOMscripted(); } else if (typeof next === 'function') { Promise.resolve(next())