开发者

Is it possible to include only the part of jQuery library which is being used?

开发者 https://www.devze.com 2023-03-19 07:27 出处:网络
Suppose I am only using a f开发者_开发问答ew 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?

Suppose I am only using a f开发者_开发问答ew 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.


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.


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.


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).


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...


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消