Created
November 14, 2011 15:08
-
-
Save Munter/1364127 to your computer and use it in GitHub Desktop.
Javascript delayed loading function
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
var defer = function (config) { | |
var inc; | |
if (config.id && !document.getElementById(config.id)) { | |
inc = document.createElement('script'); | |
if (config.id) { | |
inc.id = config.id; | |
} | |
inc.async = true; | |
inc.src = config.url; | |
inc.onload = config.callback || function () {}; | |
document.getElementsByTagName('head')[0].appendChild(inc); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment