Skip to content

Instantly share code, notes, and snippets.

@Munter
Created November 14, 2011 15:08
Show Gist options
  • Save Munter/1364127 to your computer and use it in GitHub Desktop.
Save Munter/1364127 to your computer and use it in GitHub Desktop.
Javascript delayed loading function
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