How to build a custom lightweight jQuery

Size of jQuery can be reduced easily, and you don't even need to leave the command line.

Especially the 2.x of jQuery, can be stripped to be pretty light if needed, by by getting rid of unused modules, like Ajax. As great Ajax is, it’s just not needed in many projects.

A tool to do that is the aptly named jquery-builder, which is a node app (if you don’t have Node installed yet, simply get the installer and double click it).

jQuery builder

Get the jquery-builder with npm:

$ npm install -g jquery-builder

The syntax is as follows:

$ jquery-builder --exclude <module>,<module2> > outputfile.js

If run without the output file specified it just barfs it to the command prompt and it can be copied from there. --exclude will define the modules wanted to be dropped.

Effects and ajax might be useless in some projects, for example:

$ jquery-builder --exclude effects,ajax > jquery-custom.js

By default the version is 1.11.1 (at the moment of writing this), the 2.x can be used with the --version option:

jquery-builder --exclude effects,ajax --version 2.1.1 > jquery-2.1.1.js

Note that not all the version are available via the builder, here’s a list. Also note that -v 2.0 won’t work, it needs to be exactly -v 2.0.0, the builder isn’t very smart. Also, a “latest” version option would be pretty nice :)

Here’s all the options.

  -e, --exclude   Modules to exclude [module,module]  [string]
  -m, --minify    Minify output                       [boolean]
  -l, --ls        List available modules              [boolean]
  -v, --version   Version of jQuery                   [string]  [default: "1.9.1"]
  -s, --versions  List available versions

What does each module do then?

You can get a pretty good idea by looking the jQuery docs.


There’s also a jQuery Builder website.

Club-Mate, the beverage →