Last active
April 15, 2021 06:49
-
-
Save shubham-99fusion/36000ad1940e794765609cbb4b3ab307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cssFiles = [ | |
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.12.0/css/bootstrap-tour-standalone.min.css" | |
]; | |
let jsFiles = [ | |
"https://code.jquery.com/jquery-3.6.0.min.js" | |
]; | |
alert('loading start') | |
let allPromises = []; | |
jsFiles.map((f) => { | |
allPromises.push(loadfiles(f, "js")); | |
console.log(f) | |
}); | |
cssFiles.map((f) => { | |
allPromises.push(loadfiles(f, "css")) | |
console.log(f) | |
}); | |
console.log(allPromises) | |
Promise.all(allPromises).then((values) => { | |
console.log(values); | |
alert('all loaded'); | |
(function () { | |
var s = document.createElement('script'); | |
s.type = 'text/javascript'; | |
s.async = true; | |
s.src = 'https://cdnjs.cloudflare.com/ajax/libs/bootstrap-tour/0.12.0/js/bootstrap-tour-standalone.min.js'; | |
var x = document.getElementsByTagName('script')[0]; | |
x.parentNode.insertBefore(s, x); | |
})(); | |
}) | |
function loadfiles(filename, type) { | |
return new Promise((resolve, reject) => { | |
let ntype = ""; | |
var fileref = "" | |
if (type == "js") { | |
ntype = "text/javascript"; | |
fileref = document.createElement('script'); | |
fileref.setAttribute("src", filename); | |
} else if (type == "css") { | |
ntype = "text/css"; | |
fileref = document.createElement('link'); | |
fileref.rel = 'stylesheet'; | |
fileref.setAttribute("href", filename); | |
} | |
if (!ntype) { | |
reject("type not defined") | |
} | |
if (!document.getElementById(filename)) { | |
fileref.setAttribute("id", filename) | |
fileref.setAttribute("type", ntype) | |
if (typeof fileref != "undefined") { | |
if (fileref.addEventListener) { | |
fileref.addEventListener('load', () => { console.log(filename); resolve(true) }, false); | |
} | |
document.getElementsByTagName("head")[0].appendChild(fileref) | |
} | |
} else { | |
resolve(true); | |
} | |
}) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment