Skip to content

Instantly share code, notes, and snippets.

@oliverturner
Created June 29, 2018 10:20
Show Gist options
  • Save oliverturner/bfa2b8eafb2bc78e284ede9c2ed92652 to your computer and use it in GitHub Desktop.
Save oliverturner/bfa2b8eafb2bc78e284ede9c2ed92652 to your computer and use it in GitHub Desktop.
Async CSS loader
const loadcss = (href, media = '') =>
new Promise(r =>
document.head.appendChild(Object.assign(
document.createElement('link'),
{
onload() { this.media = media; r() },
rel: 'stylesheet', media: 'only x', href
})
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment