npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

jquery.sp-require

v0.2.0

Published

A jQuery plugin to load JavaScript libraries dynamically

Downloads

8

Readme

$.spRequire

A jQuery plugin to load JavaScript libraries dynamically. Unlike other similar plugins, this plugin considers the loading of CSS files by default. Note that the only library that can not be loaded is the jQuery library, for obvious reasons.

See the demo folder for complete examples.

Installation

Install bower and execute the following command:

$ bower install jquery.sp-require

Distribution files are under the dist folder.

Declaring libraries

Libraries are declared in a configuration object. In the following example we have three libraries, and each library is composed by several JavaScript and CSS files. By default libraries are loaded asynchronously. That is: they can be loaded in any order. If you want a library to be loaded after other libraries, you can use the async attribute. In the below example, library3 is loaded after library2.

$.require('config', {
    libraries: {
        lib1: {
            sources: {
                js: ['js/script11.js', 'js/script12.js', 'js/script13.js'],
                css: ['css/style11.css', 'css/style12.css', 'css/style13.css']
            }
        },
        lib2: {
            sources: {
                js: ['js/script21.js', 'js/script22.js'],
                css: ['css/style21.css', 'css/style22.css']
            },
            requires: ['lib1']
        },
        // this library IS LOADED AT LAST PLACE
        // as it is a 'synchronous' library
        lib3: {
            async: false,
            sources: {
                js: ['js/script31.js'],
                css: ['css/style31.css']
            },
            requires: ['lib2']
        }
    }
});

In some cases we can simplify the configuration object. We can use a string to indicate a single element, an array of strings to indicate multiple elements or an object to indicate more complex objects. For example:

$.spRequire('config', {
    // lib1 is composed by a single script
    lib1: 'js/script1.js',
    // lib2 is composed by two scripts
    lib2: ['js/script21.js', 'js/script22.js'],
    // lib3 is composed by a single script and requires lib2
    lib3: {
        sources: 'js/script3.js',
        requires: 'lib2'
    },
    // lib4 is composed by two scripts and requires two libraries
    lib4: {
        sources: ['js/script41.js', 'js/script42.js'],
        requires: ['lib2', 'lib3']
    },
    // lib5 is composed by a single script and a single CSS file and requires three libraries
    // it is also a 'synchronous' library. That is: it is loaded after the required libraries
    lib5: {
        async: false,
        sources: {
            js: 'js/script5.js',
            css: 'css/style5.js'
        },
        requires: ['lib1', 'lib2', 'lib3']
    },
    // lib6 is composed by several scripts and CSS files and requires a single library
    // it is also a 'synchronous' library. That is: it is loaded after the required libraries
    lib6: {
        async: false,
        sources: {
            js: ['js/script61.js', 'js/script62.js', 'js/script63.js'],
            css: ['css/style61.css', 'css/style62.css']
        },
        requires: 'lib5'
    }
});

Basic usage

After declaring libraries in the configuration object, we can load them dynamically. For example:

$.spRequire(['lib1', 'lib2'], function () {
    console.log('Libraries are loaded and they are readay to be used');
});

The $.spRequire([libs...]) function returns a jQuery.Promise object, so the above example can also be written as follows:

$.spRequire(['lib1', 'lib2']).done(function () {
    console.log('Libraries are loaded and they are readay to be used');
}).fail(function () {
    console.log('An error has occurred and the libraries could not be loaded');
}).alwasy(function () {
    console.log('This function is always executed');
});