![New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions](https://cdn.sanity.io/images/cgdhsj6q/production/86e6ebdea652d20da070ebbda20134b839972db7-1024x1024.webp?w=800&fit=max&auto=format)
Security News
New axobject-query Maintainer Faces Backlash Over Controversial Decision to Support Legacy Node.js Versions
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
loadjs
Advanced tools
Changelog
3.4.0 - February 23, 2017
Readme
LoadJS is a tiny async loader for modern browsers (724 bytes).
LoadJS is a tiny async loading library for modern browsers (IE9+). It has a simple yet powerful dependency management system that lets you fetch JavaScript and CSS files in parallel and execute code after the dependencies have been met. The recommended way to use LoadJS is to include the minified source code of loadjs.js in your <html> (possibly in the <head> tag) and then use the loadjs
global to manage JavaScript dependencies after pageload.
LoadJS is based on the excellent $script library by Dustin Diaz. We kept the behavior of the library the same but we re-wrote the code from scratch to add support for success/error callbacks and to optimize the library for modern browsers. LoadJS is 724 bytes (minified + gzipped).
Here's an example of what you can do with LoadJS:
// define a dependency bundle
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar');
// execute code elsewhere when the bundle has loaded
loadjs.ready('foobar', {
success: function() { /* foo.js & bar.js loaded */ },
error: function(depsNotFound) { /* foobar bundle load failed */ }
});
The latest version of LoadJS can be found in the dist/
directory in this repository:
You can also use it as a CJS or AMD module:
$ npm install --save loadjs
var loadjs = require('loadjs');
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar');
loadjs.ready('foobar', {
success: function() { /* foo.js & bar.js loaded */ },
error: function(depsNotFound) {/* foobar bundle load failed */}
});
async: false
support only works in IE10+)LoadJS also detects script load failures from AdBlock Plus and Ghostery in:
Note: LoadJS treats empty CSS files as load failures in IE (to get around lack of support for onerror events on <link>
tags)
loadjs('/path/to/foo.js', {
success: function() { /* foo.js loaded */}
});
loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
success: function() { /* foo.js & bar.js loaded */ }
});
loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
success: function() { /* foo.js and bar.js loaded in series */ },
async: false
});
loadjs(['/path/to/foo.css', '/path/to/bar.js'], {
success: function() { /* foo.css and bar.js loaded */ }
});
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {
success: function() { /* foo.js & bar.js loaded */ }
});
if (!loadjs.isDefined('foobar')) {
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {
success: function() { /* foo.js & bar.js loaded */ }
});
}
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {
success: function() { /* foo.js & bar.js loaded */ },
error: function(pathsNotFound) { /* at least one path didn't load */ }
});
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar', {
success: function() { /* foo.js & bar.js loaded */ },
error: function(pathsNotFound) { /* at least one path didn't load */ },
numRetries: 3
});
loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
success: function() {},
error: function(pathsNotFound) {},
before: function(path, scriptEl) {
/* called for each script node before being embedded */
if (path === '/path/to/foo.js') scriptEl.crossOrigin = true;
}
});
loadjs(['/path/to/foo.js', '/path/to/bar.js'], 'foobar');
loadjs.ready('foobar', {
success: function() { /* foo.js & bar.js loaded */ }
});
loadjs('/path/to/foo.js', 'foo');
loadjs('/path/to/bar.js', 'bar');
loadjs
.ready('foo', {
success: function() { /* foo.js loaded */ }
})
.ready('bar', {
success: function() { /* bar.js loaded */ }
});
loadjs('/path/to/foo.js', 'foo');
loadjs('/path/to/bar.js', 'bar');
loadjs(['/path/to/thunkor.js', '/path/to/thunky.js'], 'thunk');
// wait for multiple depdendencies
loadjs.ready(['foo', 'bar', 'thunk'], {
success: function() {
// foo.js & bar.js & thunkor.js & thunky.js loaded
},
error: function(depsNotFound) {
if (depsNotFound.indexOf('foo') > -1) {}; // foo failed
if (depsNotFound.indexOf('bar') > -1) {}; // bar failed
if (depsNotFound.indexOf('thunk') > -1) {}; // thunk failed
}
});
loadjs.ready(['dependency1', 'dependency2'], {
success: function() {
// run code after dependencies have been met
}
});
function fn1() {
loadjs.done('dependency1');
}
function fn2() {
loadjs.done('dependency2');
}
loadjs.reset();
loadjs/ ├── dist │ ├── loadjs.js │ ├── loadjs.min.js │ └── loadjs.umd.js ├── examples ├── gulpfile.js ├── LICENSE.txt ├── package.json ├── README.md ├── src │ └── loadjs.js ├── test └── umd-templates
$ git clone git@github.com:muicss/loadjs.git
$ cd loadjs
$ npm install
$ npm run build-examples
To view the examples you can use any static file server. To use the nodejs
http-server module:
$ npm install http-server
$ npm run http-server -- -p 3000
Then visit http://localhost:3000/examples
$ npm run build-dist
The files will be located in the dist
directory.
Run tests
To run the browser tests first build the loadjs
library:
$ npm run build-tests
Then visit http://localhost:3000/test
Build all files
$ npm run build-all
FAQs
Tiny async loader for modern browsers
The npm package loadjs receives a total of 175,658 weekly downloads. As such, loadjs popularity was classified as popular.
We found that loadjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.
Security News
Results from the 2023 State of JavaScript Survey highlight key trends, including Vite's dominance, rising TypeScript adoption, and the enduring popularity of React. Discover more insights on developer preferences and technology usage.
Security News
The US Justice Department has penalized two consulting firms $11.3 million for failing to meet cybersecurity requirements on federally funded projects, emphasizing strict enforcement to protect sensitive government data.