Skip to content

Instantly share code, notes, and snippets.

@ryanhanwu
Created April 13, 2012 17:11
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 ryanhanwu/2378420 to your computer and use it in GitHub Desktop.
Save ryanhanwu/2378420 to your computer and use it in GitHub Desktop.
Do not use document write to create script tag
//Do not use docwrite
document.write('<script src="' + src + '" type="text/javascript"><\/script>'):
//Use Async
var newScript = document.createElement("script");
newScript.async = true;
newScript.src = "http://xxxxxxxxxxxxxxxxxxxx.js";
var s0 = document.getElementsByTagName('script')[0];
s0.parentNode.insertBefore(newScript, s0);
//Reference : http://www.stevesouders.com/blog/2009/04/27/loading-scripts-without-blocking/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment