Skip to content

Instantly share code, notes, and snippets.

@mjschranz
Created May 17, 2012 19:47
Show Gist options
  • Save mjschranz/2721194 to your computer and use it in GitHub Desktop.
Save mjschranz/2721194 to your computer and use it in GitHub Desktop.
Butter CSS Loader
var scriptElement,
interval;
checkFn = checkFn || function(){
return !!scriptElement;
};
function runCheckFn() {
interval = setInterval(function(){
if( checkFn() ){
clearInterval( interval );
if( callback ){
callback();
}
}
}, CSS_POLL_INTERVAL );
}
url = fixUrl( url );
if( !checkFn() ){
scriptElement = document.createElement( "link" );
scriptElement.rel = "stylesheet";
scriptElement.onload = runCheckFn;
scriptElement.href = url;
document.head.appendChild( scriptElement );
}
else if( callback ){
callback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment