3

Suppose I am only using a few of the jQuery functions say show, hide, animate and attr. Is it possible to obtain only the part of jQuery library which implements these four functions?

I don't mind using a tool such as a compiler or some dependency checking script.

P.S: Please do not tell me that the size of the jQuery library is very small and it won't matter including it. I know this but still I want to know if it is possible.

Edit: I am asking for an automated solution.

Cracker
  • 1,780
  • 4
  • 24
  • 34
  • No, not unless you want to pull out the functions themselves, youself. – James Black Jul 10 '11 at 00:02
  • @James Black Any idea how easy or difficult is would be write a dependency checking script? – Cracker Jul 10 '11 at 00:12
  • @Cracker: Try a custom build first as sod suggests below. I've never tried it but i think if you exclude everyting but `attributes`,`core`, and `effects` youll get as close as you can. I think all those dependencies shoudl be auto tracked, but i i could be wrong.. id try it before i went monkeying about with creating my own dep checker :-) – prodigitalson Jul 10 '11 at 00:25
  • @Cracker - I expect in Javascript it could be a pain to write, as you would need to write your code, then run some javascript file that goes to github, looks through the source code, and removes what it finds, then goes back to make certain that all the functions it needs are found, and so on. I expect it would be easier to do this manually. – James Black Jul 10 '11 at 01:46

5 Answers5

5

Yes it would be possible, but non trivially painful. You'd need not only those 4 functions, but all the core functions (selectors, utility functions, etc) that those depend on. The current jquery core library and infrastructure does not provide any convenient method to do that dependency analysis: you might be able to find a javascript dependency analyzer that would let you do that smoothly, but by hand? Not pleasant.

Femi
  • 64,273
  • 8
  • 118
  • 148
3

jQuery is pretty modular. If you want to invest time into it, you could build a subset of jQuery from it's source on github.

https://github.com/jquery/jquery

I'm pretty sure you just have to remove the modules from the makefile you wanna exclude, but I never tried it myself.

sod
  • 3,804
  • 5
  • 22
  • 28
1

Yes this is possible if you want to take the time to exclude them manually.. Which would be kind of time consuming. It IS possible to leave out the extra UI Tools such as The Tabs, Tooltips or Overlay (automatically done on several websites).

Jules
  • 7,148
  • 6
  • 26
  • 50
0

If you're looking for an automated solution, Google's Closure Compiler is the best (maybe only?) in the business. Unfortunately, jQuery is structured in such a way as to prevent the Closure Compiler from having any effect.

One of the answers in that thread indicated that the Dojo Toolkit can be used in conjunction with the Closure Compiler to remove parts of the framework that are not used. Sure, it's a different syntax compared to their "competitor" jQuery, but they're really quite similar in the big picture.

I'm a huge fan of jQuery, so I promise Dojo didn't pay me to say this, but if slimming down an existing javascript framework in an automated way is really important to you, I'm afraid the only answer is to ditch jQuery.

Hope this helps...

Community
  • 1
  • 1
ElonU Webdev
  • 2,451
  • 14
  • 15
0

looking at the source, functionality is added in chunks. Each chunk added with

jQuery.extend({
});

So, I suppose you could try excluding modules and testing whether it still works.

Finally after removing modules and testing you will then need to compress the file otherwise you would have wasted your time.

QuentinUK
  • 2,997
  • 21
  • 20