views:

95

answers:

4

Well, I am using jQuery in my project, but I really don't use any effects, only the $.ajax function, is there a way to make jQuery .js file only contain that function or maybe a similar function that doesn't depends on jQuery?

I am coding a library, so I don't want to have a jQuery dependence.

+3  A: 

There isn't an easy way to do this, the library is built as a library, meant to be intact. Getting only what you want is easy...getting all dependencies for those methods is a different matter. It's really not worth the trouble for the size you'll save, and the pain you'll experience repeating this for every new jQuery release you update to.

The library is minified (which you should be using in production) and should be delivered via gzip, you're actually transferring very little to the client, and they should be caching it after the first time, if your headers are set correctly.

Nick Craver
+1, great answer.
Alex
A: 

This seems like a case of premature optimization (which is the root of all evil ;)). Basically you won't gain anything from this. Basically you could just as well write the XHRs by hand in pure javascript.

Uku Loskit
+1  A: 

If the only thing you need is Ajax functionality, why not try the jx library?

http://www.openjs.com/scripts/jx/

Jeff
It's very small, seems good, thanks!
M28
I see that you're coding a library. You could either list jx as a dependency, or actually just incorporate the jx code into your file in the same way that jQuery incorporates Sizzle.
Jeff
I'll incorporate it.
M28
@Jeff - To be clear to those unaware, Sizzle is included in jQuery as part of the build process, it's directly in the code, not copied into the jQuery library itself.
Nick Craver
A: 

You could always (but I really don't recommend it) extract the methods you need form the source code: jQuery source. Or if you only use the ajax functionality you could build you own ajax methods. Checkout w3's guide of ajax Ajax tutorial

..fredrik

fredrik