Skip to content

Instantly share code, notes, and snippets.

@felquis
Created June 8, 2020 21:24
Show Gist options
  • Save felquis/3ccc90d95dd55a4770eae48d300c0f8b to your computer and use it in GitHub Desktop.
Save felquis/3ccc90d95dd55a4770eae48d300c0f8b to your computer and use it in GitHub Desktop.
Yet Another Snippet to load global stylesheets
/*
Usage: loadStyles([{
href:
'https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons',
},
{
href:
'https://unpkg.com/bootstrap-material-design@4.0.0-beta.4/dist/css/bootstrap-material-design.min.css',
integrity:
'sha384',
},
{
href: 'https://unpkg.com/normalize.css@^4.1.1',
},
])
*/
const loadStyles = list => {
return Promise.all(list.map((file) => {
return new Promise((resolve, reject) => {
const link = document.createElement('link');
link.rel = 'stylesheet';
Object.keys(file).forEach(propertyName => {
link[propertyName] = file[propertyName];
});
link.onload = () => resolve();
link.onerror = () => reject();
document.body.appendChild(link);
})
}))
};
module exports loadStyles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment