Skip to content

Commit 9876d37

Browse files
committed
Load scripts in parallel instead of sequentially
To run scripts in the right order, currently we are loading them sequentially by hand (by waiting for their load event). By injecting scripts all at once, but using `defer`, we keep the execution order in place (important!), while still allowing parallelization of network requests.
1 parent 86eb9df commit 9876d37

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vendor/embed.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
if (script.content) {
2222
scriptTag.textContent = script.content;
2323
}
24+
scriptTag.defer = true;
25+
scriptTag.async = false;
26+
2427
head.appendChild(scriptTag);
2528
if (!hasSrc) {
2629
resolve();
@@ -29,9 +32,9 @@
2932
}
3033

3134
async function injectScripts(scripts, head, host) {
32-
for (let script of scripts) {
33-
await injectScript(script, head, host);
34-
}
35+
await Promise.all(
36+
scripts.map((script) => injectScript(script, head, host))
37+
);
3538
}
3639

3740
function injectLinks(links, head, host) {

0 commit comments

Comments
 (0)