# dynload

> Basic script loader

Latest version **1.0.2** (published 2017-02-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install dynload
pnpm add dynload
yarn add dynload
bun add dynload
```

## 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 | 1.0.2 |
| Published | 2017-02-23 |
| First published | 2017-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Damian Krzeminski |
| Maintainers | pirxpilot |
| Keywords | browser, loader |

## Links

- npm: https://www.npmjs.com/package/dynload
- Repository: https://github.com/pirxpilot/dynload
- Issues: https://github.com/pirxpilot/dynload/issues
- npm.io page: https://npm.io/package/dynload

## 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

- 1.0.2 (latest) — 2017-02-23

## README

# load

Basic script loader.

The simplest and fastest way of loading scripts in modern browser is simply [listing them at the
end of the body element][1].

Use load only if for some reason you need to load your scripts dynamically - useful when
integrating various 3rd party widgets and snippets (google analytics, disqus, twitter API etc.) on
your page.

## Installation

Install with [npm]:

    $ npm install dynload

## API

```javascript
var load = require('dynload');
load('//topic.disqus.com/count.js');
```

Please note that scripts added to the DOM are `async` by default (see this [article][1] on script
loading) which means that they will start executing as soon as they load in pretty much random
order.

You can force async to `false` but some browsers will ignore it.

```javascript
load('//topic.disqus.com/count.js', false);
```

`load` returns [script element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLScriptElement) - you can register `onerror` and `onload` callbacks

```javascript
load('//cdn/script.js').onload =  function () {
  console.log('my script loaded');
});
```

and:

```javascript
load('//cdn/script.js').onerror =  function (err) {
  console.log('cannot load script', err);
});
```

If you your callback work with IE use [segmentio/script-onload](https://github.com/segmentio/script-onload)

```javascript
var load  = require('dynload');
var onload = require('script-onload');

onload(load('//cdn/script.js'), function(err) {
  if (err) {
    console.log('Cannot load script', err);
  } else {
    console.log('Script loaded');
  }
});
```

## License

  MIT

[1]: http://www.html5rocks.com/en/tutorials/speed/script-loading/
[npm]: https://www.npmjs.org/

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