Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Load CSS] and return #promise #ES6 #CSS
// https://polyfill.io/v3/polyfill.min.js?flags=gated&features=Promise
var loadCSS = function ( href ) {
return new Promise( function( resolve, reject ) {
var cssIsLoaded = document.querySelectorAll("link[href='" + href + "']").length > 0;
if(cssIsLoaded){
return resolve();
}
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.href = href;
document.head.appendChild( link );
link.onload = function() {
resolve();
};
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment