I have five external JavaScript files that are making the page wait to load before these files are finished loading.
I've been reading a lot about removing render-blocking javascript and it seems like the best way to do this is using the code below to let the page load before loading javascript.
The only problem is that I can't get this code to work on my website.
I've tried to place it both before and after the end-body tag, but nothing is happening.
Am I missing anything? Something wrong in the code or something else I have to do?
Thanks!
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "yourjavascripttoload.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
else window.onload = downloadJSAtOnload;
</script>