Socket
Book a DemoInstallSign in
Socket

@dan503/load-js

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@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.

1.0.7
latest
Source
npmnpm
Version published
Weekly downloads
15
-34.78%
Maintainers
1
Weekly downloads
 
Created
Source

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 which comes bundled with Node.js.

npm i @dan503/load-js

Usage

// 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 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.

Keywords

load

FAQs

Package last updated on 28 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.