Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/fengyuanchen/load-scripts
- Owner: fengyuanchen
- License: mit
- Created: 2018-04-11T14:08:02.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2021-09-21T06:11:02.000Z (over 3 years ago)
- Last Synced: 2024-11-06T07:20:26.158Z (about 2 months ago)
- Topics: browser, loader, promise, script
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/load-scripts
- Size: 104 KB
- Stars: 10
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
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/)