Async load JS file


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



Copy this code and paste it in your HTML
  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. })();

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.