Asyncronous JavaScript loader and dependency manager
Last updated 4 years ago by rstacruz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @rstacruz/scriptjs 
SYNC missed versions from official npm registry.


Async JavaScript loader & dependency manager

scriptjs is an asynchronous JavaScript loader and dependency manager with an astonishingly impressive lightweight footprint. Like many other script loaders, $script.js allows you to load script resources on-demand from any URL and not block other resources from loading (like CSS and images). Furthermore, it's unique interface allows developers to work easily with even the most complicated dependencies, which can often be the case for large, complex web applications.

Fork information

:warning: This is a fork by @rstacruz of script.js originally by Dustin Diaz, formerly in ded/script.js. This fork adds no functionality, but cleans up the code a bit.

  • Removes the smoosh-based build system
  • Replaces the browser tests with jsdom-based unit tests
  • Ender support is removed
  • Documentation is improved
  • Renamed from $script.js to the less-ambiguous scriptjs

Browser Support

  • IE 6+
  • Opera 10+
  • Safari 3+
  • Chrome 1+
  • Firefox 2+


old school - blocks CSS, Images, AND JS!

<script src="jquery.js"></script>
<script src="my-jquery-plugin.js"></script>
<script src="my-app-that-uses-plugin.js"></script>

middle school - loads as non-blocking, but has multiple dependents

$script('jquery.js', function () {
  $script('my-jquery-plugin.js', function () {

new school - loads as non-blocking, and ALL js files load asynchronously

// load jquery and plugin at the same time. name it 'bundle'
$script(['jquery.js', 'my-jquery-plugin.js'], 'bundle')

// load your usage

/*--- in my-jquery-plugin.js ---*/
$script.ready('bundle', function() {
  // jquery & plugin (this file) are both ready
  // plugin code...

/*--- in my-app-that-uses-plugin.js ---*/
$script.ready('bundle', function() {
  // use your plugin :)

Exhaustive list of ways to use $script.js

$script('foo.js', function() {
  // foo.js is ready

$script(['foo.js', 'bar.js'], function() {
  // foo.js & bar.js is ready

$script(['foo.js', 'bar.js'], 'bundle')
$script.ready('bundle', function() {
  // foo.js & bar.js is ready

// create an id and callback inline
$script(['foo.js', 'bar.js'], 'bundle', function () {
  // foo.js & bar.js is ready

$script('foo.js', 'foo')
$script('bar.js', 'bar')
  .ready('foo', function() {
    // foo.js is ready
  .ready('bar', function() {
    // bar.js is ready

var dependencyList = {
    foo: 'foo.js'
  , bar: 'bar.js'
  , thunk: ['thunkor.js', 'thunky.js']

$script('foo.js', 'foo')
$script('bar.js', 'bar')

// wait for multiple depdendencies!
$script.ready(['foo', 'bar', 'thunk'], function () {
  // foo.js & bar.js & thunkor.js & thunky.js is ready
}, function(depsNotFound) {
    // foo.js & bar.js may have downloaded
    // but ['thunk'] dependency was never found
    // so lazy load it now
    depsNotFound.forEach(function(dep) {
      $script(dependencyList[dep], dep)

// in my-awesome-plugin.js
$script.ready('jquery', function() {
  //define awesome jquery plugin here

// in index.html
$script('jquery.js', 'jquery')
$script.ready('my-awesome-plugin', function() {
  //run code here when jquery and my awesome plugin are both ready



Optionally to make working with large projects easier, there is a path variable you can set to set as a base.

$script(['dom', 'event'], function () {
  // use dom & event

Note that this will include all scripts from here on out with the base path. If you wish to circumvent this for any single script, you can simply call $script.get()

$script(['dom', 'event'], function () {
  // use dom & event

$script.get('http://example.com/base.js', function () {



As of 2.5.5 it's possible to concat URL arguments (i.e. a query string) to the script path. This is especially useful when you're in need of a cachebuster and works as follows:


Please note that Squid, a popular proxy, doesn’t cache resources with a querystring. This hurts performance when multiple users behind a proxy cache request the same file – rather than using the cached version everybody would have to send a request to the origin server. So ideally, as Steve Souders points out, you should rev the filename itself.

Current Tags

  • 3.0.0                                ...           latest (4 years ago)

1 Versions

  • 3.0.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
Dev Dependencies (6)
Dependents (0)

Copyright 2014 - 2017 © taobao.org |