Script.js - Asynchronous JavaScript Loader

2.5.9 · maintenance · verified Sun Apr 19

$script.js is a compact, asynchronous JavaScript loader and dependency manager designed for browser environments. Its primary function is to load JavaScript resources on demand without blocking the rendering of other assets like CSS and images, a common issue with traditional `<script>` tags. The library, currently at version 2.5.9, focuses on simplifying dependency management for complex web applications by allowing scripts to be loaded in parallel and executed once their dependencies are met, using a unique `ready` callback mechanism. It differentiates itself through its lightweight footprint and its ability to manage intricate load sequences using named bundles or individual script IDs, making it suitable for older browser environments (IE6+, Opera10+). However, its release cadence appears to be very slow, with the last known stable version 2.5.9 released quite some time ago, indicating a maintenance or effectively abandoned status given the prevalence of modern bundlers.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates loading multiple scripts, grouping them into a bundle, setting a base path, and using the `$script.ready` callback for deferred execution based on named dependencies.

$script.path('/assets/js/');

// Load jQuery and a jQuery plugin concurrently, assigning them to a 'vendor' bundle ID
$script(['jquery-3.x.min.js', 'my-jquery-plugin.js'], 'vendor', function() {
  console.log('jQuery and plugin loaded. Initializing application...');
});

// Load a core application module separately
$script('app-core.js', 'appCore');

// Wait for both the 'vendor' bundle and 'appCore' module to be ready
$script.ready(['vendor', 'appCore'], function() {
  console.log('All core scripts are loaded and ready.');
  // Application initialization code that depends on all these scripts
  // For example, if jQuery is globally available via `window.$`
  if (typeof window.$ !== 'undefined') {
    console.log('jQuery version:', $.fn.jquery);
  }
  // Your application's main entry point
  // myApp.init();
}, function(depsNotFound) {
  console.error('Some dependencies were not found:', depsNotFound);
  // Optionally, try to lazy load missing dependencies
});

view raw JSON →