Skip to content

Instantly share code, notes, and snippets.

@gasolin
Last active December 23, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gasolin/6578178 to your computer and use it in GitHub Desktop.
Save gasolin/6578178 to your computer and use it in GitHub Desktop.
async download DOM and allow cross domain JS by Script DOM element
var dom = document.createElement('script');
dom.src = "http://xxx/a.js";
document.head.appendChild(dom);
@gasolin
Copy link
Author

gasolin commented Sep 16, 2013

or document.head.appendChild(dom);

refer to shared/js/lazy_loader.js

@gasolin
Copy link
Author

gasolin commented Sep 16, 2013

sample from even faster web sites

@gasolin
Copy link
Author

gasolin commented Sep 16, 2013

to ensure execute after load: script load method

`
var dom = document.createElement('script');
dom.src = "http://xxx/a.js";

dom.onloadDone = false;
dom.onload = function() {
dom.onloadDone = true;
init();
}

document.head.appendChild(dom);
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment