# load-script

> Dynamic script loading for browser

Latest version **2.0.0** (published 2021-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install load-script
pnpm add load-script
yarn add load-script
bun add load-script
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2021-10-06 |
| First published | 2013-05-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 149 |
| Maintainers | eldar, rauchg, defunctzombie |
| Keywords | browser, script, load |

## Links

- npm: https://www.npmjs.com/package/load-script
- Repository: https://github.com/eldargab/load-script
- Homepage: https://github.com/eldargab/load-script#readme
- Issues: https://github.com/eldargab/load-script/issues
- npm.io page: https://npm.io/package/load-script

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2021-10-06
- 1.0.0 — 2015-03-08
- 0.0.5 — 2014-03-21
- 0.0.4 — 2013-12-31
- 0.0.3 — 2013-12-28
- 0.0.2 — 2013-05-29

## README

# load-script

Dynamic script loading.

## Installation

via component

```
$ component install eldargab/load-script
```

via npm

```
$ npm install load-script
```

## API
`load-script` appends a `script` node to the `<head>` element in the dom.

`require('load-script')` returns a function of the following interface:  `function(url[, opts][, cb]) {}`

### url
Any url that you would like to load.  May be absolute or relative.

### [, opts]
A map of options.  Here are the currently supported options:

* `async` - A boolean value used for `script.async`.  By default this is `true`.
* `attrs` - A map of attributes to set on the `script` node before appending it to the DOM.  By default this is empty.
* `charset` - A string value used for `script.charset`.  By default this is `utf8`.
* `text` - A string of text to append to the `script` node before it is appended to the DOM.  By default this is empty.
* `type` - A string used for `script.type`.  By default this is `text/javascript`.

### [, cb]
A callback function of the following interface: `function(err, script) {}` where `err` is an error if any occurred and `script` is the `script` node that was appended to the DOM.

## Example Usage

```javascript
var load = require('load-script')

load('foo.js', function (err, script) {
  if (err) {
    // print useful message
  }
  else {
    console.log(script.src);// Prints 'foo'.js'
    // use script
    // note that in IE8 and below loading error wouldn't be reported
  }
})
```

## License

MIT

---
_Source: https://npm.io/package/load-script · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
