Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fengyuanchen/load-scripts

Dynamic scripts loading for modern browsers.
https://github.com/fengyuanchen/load-scripts

browser loader promise script

Last synced: about 1 month ago
JSON representation

Dynamic scripts loading for modern browsers.

Awesome Lists containing this project

README

        

# load-scripts

[![Downloads](https://img.shields.io/npm/dm/load-scripts.svg)](https://www.npmjs.com/package/load-scripts) [![Version](https://img.shields.io/npm/v/load-scripts.svg)](https://www.npmjs.com/package/load-scripts) [![Gzip Size](https://img.shields.io/bundlephobia/minzip/load-scripts.svg)](https://unpkg.com/load-scripts/dist/load-scripts.js)

> Dynamic scripts loading for modern browsers.

## Main files

```text
dist/
├── load-scripts.js (UMD, default)
├── load-scripts.min.js (UMD, compressed)
├── load-scripts.esm.js (ECMAScript Module)
├── load-scripts.esm.min.js (ECMAScript Module, compressed)
└── load-scripts.d.ts (TypeScript Declaration File)
```

## Getting started

### Installation

```shell
npm install load-scripts
```

In browser:

```html

```

### Usage

#### Syntax

```js
loadScripts(script1, script2, ..., scriptN)
.then(() => {})
.catch((err) => {})
.finally(() => {});
```

#### Example

```js
import loadScripts from 'load-scripts';

loadScripts('foo.js').then(() => {
console.log(window.Foo);
});

loadScripts('foo.js', 'bar.js').then(() => {
console.log(window.Foo, window.Bar);
});
```

In browser:

```html

loadScripts('foo.js').then(() => {
console.log(window.Foo);
});

```

## Browser support

- Chrome (latest)
- Firefox (latest)
- Safari (latest)
- Opera (latest)
- Edge (latest)
- Internet Explorer 10+ (requires a `Promise` polyfill as [es6-promise](https://github.com/stefanpenner/es6-promise))

## Versioning

Maintained under the [Semantic Versioning guidelines](https://semver.org/).

## License

[MIT](https://opensource.org/licenses/MIT) © [Chen Fengyuan](https://chenfengyuan.com/)