Currently, I am working on optimizing my website according to Google's PageSpeed Insights recommendations. One of the suggestions is to "Remove Render-Blocking JavaScript" for a few files (for simplicity, let's call them 1.js, 2.js, and 3.js).
To address this issue, I am following Patrick Sexton's approach of "Defer Loading Javascript" by deferring only one file named defer.js:
<script type="text/javascript">
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.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>
My query now is: How can I tweak this method to include multiple files such as 1.js, 2.js, and 3.js?