0.0.3 • Published 4 years ago

load-script-or-css v0.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

load-script-or-css

Load a script or stylesheet in the browser asynchronously, returning a Promise

Usage

const {loadCss, loadScript} = require('load-script-or-css')

// Load one Stylesheet
await loadCss('http://unpkg.com/bootstrap/dist/css/bootstrap.min.css')

// Load one script
await loadScript('http://unpkg.com/bootstrap/dist/js/bootstrap.min.js')

// load a stylesheet and a script
await Promise.all([
  loadCss('http://unpkg.com/bootstrap/dist/css/bootstrap.min.css'),
  loadScript('http://unpkg.com/bootstrap/dist/js/bootstrap.min.js')
])

// load a stylesheet and a script, but don’t fail if one
await Promise.all([
  loadCss('http://unpkg.com/bootstrap/dist/css/bootstrap.min.css').dontThrow(),
  loadScript('http://unpkg.com/bootstrap/dist/js/bootstrap.min.js').dontThrow()
])