Created
July 14, 2012 05:53
-
-
Save selwin/3109598 to your computer and use it in GitHub Desktop.
Async javascript loading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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