Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reduce jQuery?

Tags:

jquery

I'm using just a few basic jQuery functions on my site.
How can I remove unused jQuery code?
Knowing only the basics, I looked at the code and was not sure where to start. If you could point me in the right direction, that would be appreciated.

Thanks.

like image 909
T.T.T. Avatar asked Apr 28 '10 23:04

T.T.T.


2 Answers

jQuery itself isn't really built to be selectively used. There are lots of interdependencies between its own functions and the source isn't laid out to be easy to modularise. Unlike the situation with plugins like jQuery-UI, the core of jQuery is pretty much take-it-or-leave-it.

If you've only used a few simple functions, you might be able to rewrite them in plain JavaScript. If the main function you're using is selectors you can use Sizzle, which is the underlying selector library that jQuery itself uses. Otherwise... not really.

like image 99
bobince Avatar answered Nov 03 '22 00:11

bobince


If you want to further reduce the code size, minify and gzip or deflate it. Beware that gzipped code needs to be uncompressed before it's executed, thus causing a delay. The jQuery download page offers an already minified and gzipped version.

Another option you could look into is using CND hosted jQuery, that is jQuery hosted by third party organizations such as Google or Microsoft. Details in the jQuery download page.

like image 35
Cesar Avatar answered Nov 02 '22 22:11

Cesar