victorpavlov
11/18/2013 - 10:04 AM

JavaScript asynchronously without blocking onload. From http://www.phpied.com/non-onload-blocking-async-js/

JavaScript asynchronously without blocking onload. From http://www.phpied.com/non-onload-blocking-async-js/

(function(url){
  var iframe = document.createElement('iframe');
  (iframe.frameElement || iframe).style.cssText = "width: 0; height: 0; border: 0";
  var where = document.getElementsByTagName('script');
  where = where[where.length - 1];
  where.parentNode.insertBefore(iframe, where);
  var doc = iframe.contentWindow.document;
  doc.open().write('<body onload="'+
    'var js = document.createElement(\'script\');'+
    'js.src = \''+ url +'\';'+
    'document.body.appendChild(js);">');
  doc.close();
})('http://www.jspatterns.com/files/meebo/asyncjs1.php');