Skip to content

Instantly share code, notes, and snippets.

@selwin
Created July 14, 2012 05:53
Show Gist options
  • Save selwin/3109598 to your computer and use it in GitHub Desktop.
Save selwin/3109598 to your computer and use it in GitHub Desktop.
Async javascript loading
// 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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment