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:
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.
- Firstly we have to install git and NodeJS:
- 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:
sudo apt-get install nodejs git
npm install -g grunt-cli
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:
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.