Skip to content

Instantly share code, notes, and snippets.

@marcus-at-localhost
Last active January 3, 2023 14:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save marcus-at-localhost/514ce85df6fb3ab10719a7cacce50770 to your computer and use it in GitHub Desktop.
[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