Zepto 和 jQuery 2 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14830334/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between Zepto and jQuery 2?
提问by jantimon
There are those two similar projects:
有这两个类似的项目:
Zepto is a minimalist JavaScript library for modern browsers with a largely jQuery-compatible API.
Zepto 是一个极简的 JavaScript 库,适用于现代浏览器,具有很大程度上与 jQuery 兼容的 API。
jQuery 2.0 beta: Here is your taste of the future, a jQuery that can be faster and smaller without the need to support IE 6, 7, or 8. It's a great choice for platform-specific HTML applications.
jQuery 2.0 测试版:这是您对未来的品味,一个可以更快更小且无需支持 IE 6、7 或 8 的 jQuery。它是特定于平台的 HTML 应用程序的绝佳选择。
Is this only about performance or do they follow different approaches?
这仅仅是关于性能还是他们遵循不同的方法?
采纳答案by MHD
The primary difference between Zepto.js and jQuery are their respective file sizes of Zepto.js's ~20kb (minified, not gzipped) instead of jQuery's ~80kb,And Zepto.js's ~10kb (minified, Gzipped) instead of jQuery's ~30kb. Furthermore, Zepto's support for browsers such as IE<10
is either lacking or not guaranteed, its target platformsare:
Zepto.js 和 jQuery 的主要区别在于它们各自的文件大小,分别是 Zepto.js 的 ~20kb(缩小,而不是 gzipped)而不是 jQuery 的 ~80kb,以及 Zepto.js 的 ~10kb(缩小,Gzipped)而不是 jQuery 的 ~30kb。此外,Zepto 对诸如此类的浏览器的支持IE<10
要么缺乏要么无法保证,其目标平台是:
- Safari 5+ (desktop)
- Chrome 5+ (desktop)
- Mozilla Firefox 4+
- iOS 4+ Safari
- Android 2.2+ Browser
- Other WebKit-based browsers/runtimes
- webOS 1.4.5+ Browser
- BlackBerry Tablet OS 1.0.7+ Browser
- Amazon Silk 1.0+
- Opera 10+
- Internet Explorer 10+
- Safari 5+(桌面版)
- Chrome 5+(桌面)
- 火狐浏览器 4+
- iOS 4+ Safari
- 安卓 2.2+ 浏览器
- 其他基于 WebKit 的浏览器/运行时
- webOS 1.4.5+ 浏览器
- 黑莓平板操作系统 1.0.7+ 浏览器
- 亚马逊丝绸 1.0+
- 歌剧 10+
- 浏览器 10+
回答by asparagino
jquery 2 is ~30kb and zepto is ~10kb when both are gzipped and minified. Non gzipped but minified, jquery 2 is ~80kb and zepto is ~30kb.
jquery 2 是 ~30kb 和 zepto 是 ~10kb 当两者都被压缩和缩小时。未压缩但已缩小,jquery 2 约为 80kb,zepto 约为 30kb。
Use an analytics program to check the audience for your site. If a significant chunk of your users use IE9, you need jquery and zepto won't fly. If over a few percent use IE8 and lower and you can't face leaving them stranded without your site, you will need to use jquery 1. If you're targetting that last one, I'm sorry - a lot of new shiny toys won't work for you.
使用分析程序检查您网站的受众。如果您的大量用户使用 IE9,则您需要 jquery 并且 zepto 不会飞。如果超过百分之几使用 IE8 及更低版本,并且您不能在没有您的网站的情况下让他们陷入困境,那么您将需要使用 jquery 1。如果您的目标是最后一个,对不起 - 很多新的闪亮玩具不会为你工作。
If you're building an html5 app for android/ios/phonegap etc then you're primarily targeting webkit, so zepto does give you big size saving. The primary insight and reason for zepto to exist is that when running on webkit only platforms a lot of jquery's cross platform workarounds are simply unnecessary.
如果您正在为 android/ios/phonegap 等构建 html5 应用程序,那么您主要针对 webkit,因此 zepto 确实可以节省大量资源。zepto 存在的主要见解和原因是,当仅在 webkit 平台上运行时,很多 jquery 的跨平台解决方法都是不必要的。
Zepto does also add a couple of touch event handlers to assist with mobile dev, but it's mainly the page weight vs platform support you need to think about.
Zepto 还添加了几个触摸事件处理程序来协助移动开发,但主要是您需要考虑的页面权重与平台支持。
回答by Brigand
This is a somewhat old question, but I would like to add performance. From what I'd heard, Zepto performed better than jQuery.
这是一个有点老的问题,但我想增加性能。据我所知,Zepto 的性能比 jQuery 好。
This jsPerfshows different results. I can use jQuery's class selection (of a single element) 137% as often, compared to Zepto's. For ID selection, I can use jQuery's 285% as often.
这个jsPerf显示了不同的结果。与 Zepto 相比,我可以使用 jQuery 的类选择(单个元素)137%。对于 ID 选择,我可以经常使用 jQuery 的 285%。
That's a huge deal considering on most applications, DOM interactions are the only performance statistic that matters (other than network requests).
考虑到大多数应用程序,这是一个大问题,DOM 交互是唯一重要的性能统计数据(网络请求除外)。
Also looking at that perf, I can see that I could do document.getElementsByClassNAme 8326% as often as jQuery, so we should all ditch all of these if possible :-)
另外看看那个性能,我可以看到我可以像 jQuery 一样频繁地执行 document.getElementsByClassNAme 8326%,所以如果可能的话,我们都应该放弃所有这些 :-)
回答by David M. Anderson
Zepto lacks the deferred/promise API that jQuery features. There is an add-on, Simply Deferred, which remedies this: https://github.com/sudhirj/simply-deferred.
Zepto 缺少 jQuery 具有的延迟/承诺 API。有一个附加组件,Simply Deferred,可以解决这个问题:https: //github.com/sudhirj/simply-deferred。
回答by HAROONMIND
I think never used zepto for fast wroking transition into web take a look Deep inside his icy cave, the wise and powerful Yeti heard people asking, "Where did Zepto go?" Back when Foundation 4 was being conceived we switched to Zepto (with a jQuery option) for its smaller file size and faster load time.
我想从来没有用过 zepto 快速过渡到网络看看 在他冰冷的洞穴深处,聪明而强大的雪人听到人们问:“Zepto 去哪儿了?” 回想 Foundation 4 时,我们切换到 Zepto(带有 jQuery 选项),因为它的文件更小,加载时间更快。
But over time we found that lighter file size did not translate into better performance overall. Sure, Zepto downloaded quickly. But once loaded, it wasn't quite as fast as jQuery. It didn't help that many third-party plugins required jQuery, not Zepto — in fact, we found that some third party JavaScripts conflicted outright with Zepto.
但随着时间的推移,我们发现更轻的文件大小并没有转化为更好的整体性能。当然,Zepto 下载速度很快。但是一旦加载,它就没有 jQuery 快。许多第三方插件需要 jQuery 而不是 Zepto,这无济于事——事实上,我们发现一些第三方 JavaScript 与 Zepto 完全冲突。
Maintaining different code bases wasn't easy for us, either. For example, Zepto lacks a proper height calculation function, making certain grid calculations difficult.
维护不同的代码库对我们来说也不容易。例如,Zepto 缺乏适当的高度计算功能,使得某些网格计算变得困难。
To solve all this, the answer was clear as a spring Himalayan sky: Foundation 5 uses jQuery 2. In addition to better speed and industry acceptance, jQuery 2 benefits from better documentation and support as well. jQuery is API compatible.
为了解决所有这些问题,答案就像春天的喜马拉雅天空一样清晰:Foundation 5 使用 jQuery 2。除了更好的速度和行业接受度之外,jQuery 2 还受益于更好的文档和支持。jQuery 与 API 兼容。
**
**
But we assumed Zepto would be faster than jQuery. We didn't want to make the same assumption twice, so we tested Zepto vs. jQuery 2. The result: jQuery 2 has more operations per second. That gives Foundation 5 better performance, which translates to better experience for all users.
但是我们假设 Zepto 会比 jQuery 更快。我们不想做两次相同的假设,所以我们测试了 Zepto 与 jQuery 2。结果:jQuery 2 每秒有更多的操作。这为 Foundation 5 提供了更好的性能,从而为所有用户带来了更好的体验。
**
**
In the end, we want to help people design great products faster — and this time, that means giving the most responsive front-end framework in the world itself a speed boost.
最后,我们希望帮助人们更快地设计出出色的产品——这一次,这意味着为世界上响应速度最快的前端框架本身提供速度提升。
回答by Kody
From what I've read, people seem to lean heavily towards Zepto. The most-common reasoning behind that is file-size, but jQuery 2 is actually faster than Zepto after it is loaded. Also, you won't find much support for Zepto since most people develop around jQuery. I'm not suggesting you shouldn't use Zepto, but you should look into why you want to use it and if other JavaScript libraries you are using support/conflict with it.
从我读到的内容来看,人们似乎严重倾向于 Zepto。最常见的原因是文件大小,但 jQuery 2 在加载后实际上比 Zepto 快。此外,您不会找到对 Zepto 的太多支持,因为大多数人都围绕 jQuery 进行开发。我并不是建议您不应该使用 Zepto,但您应该研究为什么要使用它,以及您使用的其他 JavaScript 库是否支持/冲突。
I would say it depends on your project. For personal or limited use, Zepto may be the better option. However, jQuery is much more supported by other libraries and if the file size is the only thing determining your reason then it is flawed. JavaScript should be loaded after the page is loaded, therefore it wouldn't hinder your page load time in either case.
我会说这取决于你的项目。对于个人或有限使用,Zepto 可能是更好的选择。但是,其他库更支持 jQuery,如果文件大小是唯一确定原因的因素,那么它就有缺陷。JavaScript 应该在页面加载后加载,因此在任何一种情况下它都不会影响您的页面加载时间。
Hereis performance test including jQuery 1.7.2, Zepto 1.0rc1, and also jQMobi 1.03.
这是性能测试,包括 jQuery 1.7.2、Zepto 1.0rc1 和 jQMobi 1.03。