-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadScripts.js
More file actions
33 lines (28 loc) · 806 Bytes
/
Copy pathloadScripts.js
File metadata and controls
33 lines (28 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
//wait for page to load
window.onload = function() {
//create array of script filenames
var scripts = [
"style.js",
"lissagen.js"
];
//get head element
var headElement = document.querySelector("head");
//define function to recursively load scripts
var injectScripts = function() {
if (scripts.length > 0) {
var scriptToLoad = scripts.shift();
//create new script element, assign source, append to page
var newScriptElement = document.createElement("script");
newScriptElement.src = scriptToLoad;
headElement.appendChild(newScriptElement);
//inject next script when current script loaded
newScriptElement.onload = function() {
injectScripts();
};
} else {
return;
}
}
injectScripts();
};