I would suggest something like this (using window.onload to really behave like defer):
$(window).load(function () { var script = document.createElement("script"); script.type = "text/javascript"; if (script.readyState) { // IE script.onreadystatechange = function () { if (script.readyState === "loaded" || script.readyState === "complete") { script.onreadystatechange = null; // do something } }; } else { // Others script.onload = function() { // do something (the same thing as above) }; } script.src = file; document.getElementsByTagName("head")[0].appendChild(script); });
If you need more than one file, put in a loop and set the file to something like the file [x]
source share