Why does Firefox randomly stop loading the <script>
tag added dynamically with js?
On this picture, I load dynamically these scripts and I add them to the dom
- "/assets/js/lib/socket.io-1.3.6.js"
- "/assets/js/lib/tweenmax.min.js"
- "/assets/js/lib.js"
- "/assets/js/module.js"
- "/assets/js/modules"
Quite randomly, the result is this, a big lag between a random script loaded dynamically and the rest of the scripts ( between 7-15s )
I actually load my scripts like that
function(url, callback){
var elem = document.createElement("script");
elem.async = true;
elem.src = url;
elem.type = "text/javascript";
elem.onload = callback;
document.getElementsByTagName("body")[0].appendChild(elem);
}
EDIT:
When I add scripts tags in my html page, the lag doesn't appear, it only appears when I load the scripts with JavaScript. But I actually need to load these scripts with JavaScript.
There is a fiddle of the bug https://jsfiddle.net/ccgb0hqr/ If the alert show up instantly refresh the page until the bug happens