Async load any number of remote JS resources


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function async_js(){
  2. scripts = []
  3. scripts[0] = "http://connect.facebook.net/en_US/all.js#xfbml=1";
  4. scripts[1] = "http://platform.twitter.com/widgets.js";
  5.  
  6. $.each(scripts, function(index){
  7. var s = document.createElement('script');
  8. s.type = 'text/javascript';
  9. s.async = true;
  10. s.src = scripts[index];
  11. var x = document.getElementsByTagName('script')[0];
  12. x.parentNode.insertBefore(s, x);
  13. });
  14.  
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.