Last active
January 3, 2023 14:36
Star
You must be signed in to star a gist
[Load CSS] and return #promise #es6 #css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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