# @dan503/load-js

> A small function for loading a js file before running code. It will only ever load the file once per page load even if called multiple times.

Latest version **1.0.7** (published 2021-11-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dan503/load-js
pnpm add @dan503/load-js
yarn add @dan503/load-js
bun add @dan503/load-js
```

## 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.7 |
| Published | 2021-11-28 |
| First published | 2020-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Daniel Tonon |
| Maintainers | dan503 |
| Keywords | load, js |

## Links

- npm: https://www.npmjs.com/package/@dan503/load-js
- Repository: https://github.com/Dan503/load-js
- Homepage: https://github.com/Dan503/load-js#readme
- Issues: https://github.com/Dan503/load-js/issues
- npm.io page: https://npm.io/package/@dan503/load-js

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.7 (latest) — 2021-11-28
- 1.0.7-beta.0 (beta) — 2021-11-28
- 1.0.6 — 2021-10-04
- 1.0.6-beta.0 — 2021-10-04
- 1.0.5 — 2021-09-19
- 1.0.4 — 2020-10-22
- 1.0.3 — 2020-10-17
- 1.0.2 — 2020-08-23
- 1.0.1 — 2020-08-19
- 1.0.1-beta.1 — 2020-08-19
- 1.0.0 — 2020-08-19
- 1.0.0-beta.1 — 2020-08-19
- 1.0.0-beta.0 — 2020-08-19

## README

# load-js

A small function for loading a js file before running code.

This function is ideal for loading up something like a polyfill before running code that is dependant on that polyfill.

## Install

Install using [npm](https://www.npmjs.com/) which comes bundled with [Node.js](https://nodejs.org/en/).

```
npm i @dan503/load-js
```

## Usage

```js
// Import using one of these 2 methods
import loadJS from '@dan503/load-js' // ES Module import syntax
var loadJS = require('@dan503/load-js').default // Common JS import syntax

// Use the first parameter to point to where the external js file needs to be downloaded from.
loadJS('https://www.website.com/js-file.js', () => {
	// The 2nd parameter is a callback function.
	// The callback will be called once the JS file has finished downloading.
})
```

## Key features

### Call multiple times, only download the file once

It will only ever download the target file **once per page load** even if called multiple times.

### Trigger callback immediately if the file is already downloaded

If the script has already been downloaded, it will trigger the callback function immediately in a synchronous fashion.

### Callbacks retain source order

It will call all of the callbacks in the order that they were declared in when the script has finished loading.

### Super simple syntax

As you can see from the usage example above, the usage syntax is extremely simple and easy to remember.

### Quality assured with Cypress tests

This project uses [Cypress](https://www.cypress.io/) end to end tests to ensure the function does what it is supposed to.

### Supports TypeScript

This function has been written in TypeScript so it has full TypeScript support built in.

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