Skip to content

Instantly share code, notes, and snippets.

@siriokun
Created August 28, 2013 17:34
Show Gist options
  • Save siriokun/6368836 to your computer and use it in GitHub Desktop.
Save siriokun/6368836 to your computer and use it in GitHub Desktop.
Append Javascript to head tag in HTML, so it not blocking rendering.
(function(){
var yourscript = document.createElement('script');
yourscript.type = 'text/javascript';
yourscript.async = true;
yourscript.src = 'http://domain.tld/path/to.js';
(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(yourscript);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment