Posted By

tennison on 11/23/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

AllKnightAccess


Async load JS file


 / Published in: JavaScript
 

URL: http://friendlybit.com/js/lazy-loading-asyncronous-javascript/

  1. (function() {
  2. function async_load(){
  3. var s = document.createElement('script');
  4. s.type = 'text/javascript';
  5. s.async = true;
  6. s.src = 'http://yourdomain.com/script.js';
  7. var x = document.getElementsByTagName('script')[0];
  8. x.parentNode.insertBefore(s, x);
  9. }
  10. if (window.attachEvent)
  11. window.attachEvent('onload', async_load);
  12. else
  13. window.addEventListener('load', async_load, false);
  14. })();

Report this snippet  

You need to login to post a comment.