admin管理员组文章数量:1325236
Edit (2012-04-12): Since this question was asked it is now possible (as of jQuery 1.8) to make custom builds of jQuery.
For most JavaScript projects that I work on, I want a simple, light-weight UI stack.
Currently I use jQuery in my projects, however when I actually take a step back and look at the code, I'm only really using it for:
- DOM traversal
- jQuery.ajax
- and Deferred
Is there another library (I don't want to handle all the various cross-browser & ES3/ES5 differences myself) that can provide me these features without all the additon stuff that I personally don't need?
Dojo springs to mind, but I have little experience with that so far, and would ideally like to hear from those who have used multiple libraries on this.
Edit (2012-04-12): Since this question was asked it is now possible (as of jQuery 1.8) to make custom builds of jQuery.
For most JavaScript projects that I work on, I want a simple, light-weight UI stack.
Currently I use jQuery in my projects, however when I actually take a step back and look at the code, I'm only really using it for:
- DOM traversal
- jQuery.ajax
- and Deferred
Is there another library (I don't want to handle all the various cross-browser & ES3/ES5 differences myself) that can provide me these features without all the additon stuff that I personally don't need?
Dojo springs to mind, but I have little experience with that so far, and would ideally like to hear from those who have used multiple libraries on this.
Share Improve this question edited Dec 4, 2012 at 15:45 isNaN1247 asked Apr 6, 2012 at 15:29 isNaN1247isNaN1247 18.1k13 gold badges74 silver badges119 bronze badges 6- Although it doesn't really answer the question - the uping 1.8 version of jQuery >should< work with closure piler in advanced mode. This means dead code removal is a possibility if it's the "unused" portions of jQuery code that are bugging you. – gnarf Commented Apr 6, 2012 at 15:32
- For your case jQuery is perfectly fine. And you are already used to it. And jQuery is pretty small - besides that, you can load it e.g. from the google or microsoft CDN where users will most likely have it already cached. – ThiefMaster Commented Apr 6, 2012 at 15:36
- I think if you include jQuery from the Google CDN a large % of your visitors will already have it cached so I wouldn't bother switching. Woops too late :) – powerbuoy Commented Apr 6, 2012 at 15:36
- Actually, given your requirements, it sounds like jQuery is the best choice for you. – Reid Commented Apr 6, 2012 at 15:54
- 1 If you're really doing DOM traversal and not manipulation, Sizzle.js is a standalone script that implements the selector portion of jQuery. It's included in jQuery files itself, but can be used independently. – harpo Commented Apr 6, 2012 at 16:18
2 Answers
Reset to default 5Take a look at http://microjs./ and use what you only need.
In minimized form, Dojo is 136kb, jQuery is 96kb. Moving to dojo is not going in the right direction.
The issues you should consider are:
- Suitability of library for your purpose
- Size of library
- Likelihood that it will be precached already
- Your familiarity with the functionality of the library
- Availability on a popular, public CDN
- Good support on the net and great documentation
- Good reputation for reliability, cross browser support and regular updates
Go through each of these and unless you find another library that scores well on these, jQuery may be your best bet. It is surprisingly pact for what it offers you and it doesn't really have a lot of stuff that isn't in your list of things you want. jQuery has done a pretty good job of keeping the core library focused on its central mission and let UI stuff go into jQueryUI and most everything else into their own plug-in libraries.
If you're obsessed about optimizing the code you include to only be the things you need, then you may want to look at YUI. It was designed to be modular so that you can specify only the modules you want and then you can prebuild a chunk of code that only has those modules in it (or you can dynamically load just the modules you want). My sense is that YUI is somewhat overdesigned in this regard and it's cumbersome to use for quick projects because you have to spend the time to figure out which modules you need and generate that build each time. Once you get a bunch of modules loaded, it's not that pact either which is where you find that jQuery is surprisingly pact for what it includes.
In general, you should not worry about the things that a library includes that you are not using. Just look at the overall size and suitability of the libraries that do meet your needs. You can probably find a library that does only what you want and is bigger than jQuery and isn't widely cached so that wouldn't be a win.
There are pact libraries out there for just ajax or just deferred, but you probably want one with ajax and deferred implemented together so you can use deferred with ajax (like jQuery has done). Libraries that do extensive DOM manipulation tend to be more than just that because they are more designed to be your core library and most people have other needs besides just DOM manipulation.
In the end, I'd suggest that you shouldn't care what your library has in it that you don't need. Just evaluate it's overall suitability vs. the alternatives.
本文标签: Alternative to jQuery when just requiring DOM traversalajax amp DeferredStack Overflow
版权声明:本文标题:Alternative to jQuery when just requiring DOM traversal, $.ajax & Deferred - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742166922a2425996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论