# @segment/load-script

> Dynamically and asynchronously load a script file.

Latest version **1.0.1** (published 2016-05-09) · SEE LICENSE IN LICENSE license · 0 weekly downloads

## Install

```sh
npm install @segment/load-script
pnpm add @segment/load-script
yarn add @segment/load-script
bun add @segment/load-script
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-05-09 |
| First published | 2016-05-09 |
| Weekly downloads | 0 |
| License | SEE LICENSE IN LICENSE |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Segment |
| Maintainers | segment |
| Keywords | DOM, iframe, load, script |

## Links

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

## Dependencies (3)

- [next-tick](https://npm.io/package/next-tick.md) ^0.2.2
- [script-onload](https://npm.io/package/script-onload.md) ^1.0.2
- [component-type](https://npm.io/package/component-type.md) ^1.2.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-05-09

## README

# load-script

[![Sauce Test Status](https://saucelabs.com/buildstatus/sio_load-script)](https://saucelabs.com/u/sio_load-script)

Component which asynchronously loads a JavaScript file by appending a script tag to the DOM.

## Installation

```sh
$ npm install @segment/load-script
```

## Examples
    
```js
var load = require('@segment/load-script');

load('//www.google-analytics.com/ga.js');
```

Load in a URL depending on the current protocol.

```js
var load = require('@segment/load-script');

load({
  http: 'http://www.google-analytics.com/ga.js',
  https: 'https://ssl.google-analytics.com/ga.js'
});
```

## API

### `loadScript(src || options, callback)`

Load the given script either by passing a `src` string, or an `options` object:

```js
{
  src: '//example.com/lib.js', // same as `src` string
  http: 'http://example.com/lib.js', // `src` to load if the protocol is `http:`
  https: 'https://ssl.example.com/lib.js' // `src` to load if the protocol is `https:`
}
```
  
You can also pass in a `callback` that will be called when the script loads with `err, event`.

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