Skip to content

Instantly share code, notes, and snippets.

@scottjehl scottjehl/head.html
Created Feb 20, 2013

What would you like to do?
simple & qualified async script load
(function( w ){
var doc = w.document,
// quick async script inject
ref = doc.getElementsByTagName( "script" )[0],
loadJS = function( src ){
var elem = doc.createElement( "script" );
elem.src = src;
ref.parentNode.insertBefore(elem, ref);
// load a script
loadJS( "foo.js" );
// or broadly qualify to newer browsers first:
if( "querySelector" in doc ){
loadJS( "foo.js" );
}( this ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.