Create Custom jQuery

Since version 1.8 of jQuery developers have started to encourage the JavaScript community to contribute more into library’s code. To do that they added a really useful feature: customization, which – as for me – should be done much earlier. Now we can download jQuery from Github project’s website in separate modules and build it the way we want.

The need

If you are reading this you probably already asked yourself a question: why the hell should I customize it, when it goes in a state as-is and its fully functional? The answer is really simple. This functionality can be useful for smaller projects and pages using multiple instances of jQuery in different scopes. Well, then it’s a shame to keep all the code library, when most of it you never gonna use it and by merely running a couple of commands, you can specify your custom version of jQuery excluding at least one of those modules:

  • ajax
  • css
  • deprecated
  • dimensions
  • effects
  • offset

By doing that we can reduce the size of the library from ~34kb to ~20kb. The result is may be not huge, but quite satisfying, and should be visible in RAM usage and website speed improvment. No more talking! Lets go.

Requirements

linux logo

For Linux/Debian
  1. Firstly we have to install git and NodeJS:
  2. sudo apt-get install nodejs git
    
  3. With NodeJS by default additionally installs GruntJS, to make sure that you’re using the newest version 0.4+ we’re gonna use some additional module installed globally:
  4. npm install -g grunt-cli
    

windows

For Windows
  1. Download and unpack msysgit and NodeJS in the same folder.
  2. Install Cygwin

Building

Now lets clone jQuery from github and install all library dependencies locally:

git clone git://github.com/jquery/jquery.git
cd jquery && npm install

Now the final step choosing modules. We can only exclude them, by selecting one or more from those:

grunt custom:-ajax,-css,-deprecated,-dimensions,-effects,-offset

One usefull functionality. To customize the output folder run grunt :

grunt params-to-exclude && grunt dist:/path/to/custom/location/

That’s everything! Easy-peasy.

If you read it, you should share it: