The best theme in WordPress theme development requires a standard protocol of enqueuing scripts through wp_enqueue_script, but this doesn't solve the problem and Google PageSpeed suffers. I found a solution given by a blogger here:
Script to call external javascript file
This code should be placed in your HTML just before the
</body>tag (near the bottom of your HTML file). I highlighted the name of the external JS file.<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>
But that will not use wp_enqueue_script. Is there any solution to do this by using wp_enqueue_script?