# load-script2

> Dynamic script loading for modern browsers

Latest version **2.0.6** (published 2020-10-27) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.6 |
| Published | 2020-10-27 |
| First published | 2017-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 45 |
| Author | Feross Aboukhadijeh |
| Maintainers | feross |
| Keywords | load, load script, load-script, load-script2, loader, loading, script, script loader, script loading |

## Links

- npm: https://www.npmjs.com/package/load-script2
- Repository: https://github.com/feross/load-script2
- Issues: https://github.com/feross/load-script2/issues
- Funding: https://github.com/sponsors/feross
- npm.io page: https://npm.io/package/load-script2

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 2.0.6 (latest) — 2020-10-27
- 2.0.5 — 2020-05-10
- 2.0.4 — 2019-11-12
- 2.0.3 — 2019-11-06
- 2.0.2 — 2019-06-28
- 2.0.1 — 2019-06-28
- 2.0.0 — 2019-06-28
- 1.0.1 — 2018-03-17
- 1.0.0 — 2017-02-21

## README

# load-script2 [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url]

[travis-image]: https://img.shields.io/travis/feross/load-script2/master.svg
[travis-url]: https://travis-ci.org/feross/load-script2
[npm-image]: https://img.shields.io/npm/v/load-script2.svg
[npm-url]: https://npmjs.org/package/load-script2
[downloads-image]: https://img.shields.io/npm/dm/load-script2.svg
[downloads-url]: https://npmjs.org/package/load-script2
[standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg
[standard-url]: https://standardjs.com

### Dynamic script loading for modern browsers

Works in the browser with [browserify](http://browserify.org/)!

## install

```
npm install load-script2
```

This package works in the browser with [browserify](https://browserify.org). If you do not use a bundler, you can use the [standalone script](https://bundle.run/load-script2) directly in a `<script>` tag.

## usage

```js
const loadScript = require('load-script2')

const script = await loadScript('foo.js')
console.log(script.src);// Prints 'foo'.js'
```

## differences to [`load-script`](https://www.npmjs.com/package/load-script)

`load-script2` does not support legacy browsers like IE8 because these browsers
do not have standards-based DOM APIs. `load-script2` also removes many esoteric
options, which aren't needed most of the time and adds **promises support**.

The size of `load-script2` is 509 bytes, compared to 655 bytes for `load-script` (minified
and gzipped).

## API

### `promise = loadScript(src, [attrs], [parentNode])`

Append a `<script>` node with the given `src` URL to the `<head>` element in the DOM.

#### `src`

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

#### `attrs` (optional)

An object that contains HTML attributes to set on the `<script>` tag. For
example, the value `{ id: 'hi' }` would set the attribute `id="hi"` on the
`<script>` tag before it is injected.

#### `parentNode` (optional)

The HTML node to which the `<script>` tag will be appended. If not specified,
defaults to the `<head>` tag.

#### `promise`

Returns a promise which resolves to the `script` node that was appended to the
DOM, or rejects with `err` if any occurred.

## license

MIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org).

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