Skip to content

Instantly share code, notes, and snippets.

@Dviejopomata
Created May 17, 2019 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dviejopomata/f8548bb9a8a3f19fd141dc49f3b692dc to your computer and use it in GitHub Desktop.
Save Dviejopomata/f8548bb9a8a3f19fd141dc49f3b692dc to your computer and use it in GitHub Desktop.
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