Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
window.PATH = "{{ client_path }}";
$(document).ready(function () {
function loadStyle(src) {
var s = document.createElement("link");
s.rel = "stylesheet";
s.src = src;
// Use any selector
$("head").append(s);
}
function loadScripts(libs) {
var injectLibFromStack = function () {
if (libs.length > 0) {
//grab the next item on the stack
var nextLib = libs.shift();
var headTag = document.getElementsByTagName('head')[0];
//create a script tag with this library
var scriptTag = document.createElement('script');
scriptTag.src = nextLib;
//when successful, inject the next script
scriptTag.onload = function (e) {
console.log("---> loaded: " + e.target.src);
injectLibFromStack();
};
//append the script tag to the <head></head>
headTag.appendChild(scriptTag);
console.log("injecting: " + nextLib);
} else return;
}
//start script injection
injectLibFromStack();
}
{% get_angular_host as angular_host %}
$.get({url: "{{ angular_host }}", cache: false}, function (data) {
var html = $(data);
var scripts = []
html.each(function () {
var tagName = $(this).prop("tagName");
if (tagName == "SCRIPT") {
var src = $(this).prop("src");
scripts.push(src)
}
if (tagName == "LINK") {
var src = $(this).prop("src");
loadStyle(src);
}
});
loadScripts(scripts)
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.