i have around 5 to 6 JavaScript which i put it at the bottom of page however I wanted to load all this JavaScript in one function so all of them download on the page Asynchronously. Can anyone suggest how can i do that? Some syntaxes will definitely helpful
`
On newer browsers you can use the async attribute:
<scritp src="yourscript.js" type="text/javascript" async=true ></script>
Or for wider support you can append the script to an already processed tag in the document:
Edit:
function loadScript (scriptpath){
var s=document.getElementsByTagName('script')[0];
var ss=document.createElement('script');
ss.type='text/javascript';
ss.async=true;
ss.src= scriptpath;
s.parentNode.insertBefore(ss,s);
}
And you can load them like so:
loadScript('script1.js');
loadScript('script2.js');
loadScript('script3.js');
loadScript('script4.js');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With