我什么时候才能直接使用Sizzle而不是jQuery?

时间:2021-03-06 16:45:37

I am a newbie to Sizzle (JavaScript selector library), interested in the following questions.

我是Sizzle(JavaScript选择器库)的新手,对以下问题感兴趣。

  1. Why would one use Sizzle instead of the jQuery core library?
  2. 为什么要使用Sizzle而不是jQuery核心库?
  3. Why was Sizzle split to a separate project from jQuery?
  4. 为什么Sizzle与jQuery分开了一个单独的项目?
  5. Are there any features that can apply to selectors that you can't achieve with the jQuery core library?
  6. 是否有任何功能可以应用于使用jQuery核心库无法实现的选择器?

4 个解决方案

#1


26  

Sizzle is much more lightweight than jQuery. jQuery is an entire DOM manipulation library and sizzle is just a selector engine. jQuery is 80kb gzipped and minified. Sizzle is 50kb uncompressed.

Sizzle比jQuery更轻量级。 jQuery是一个完整的DOM操作库,而sizzle只是一个选择器引擎。 jQuery是80kb gzip和minified。 Sizzle是50kb未压缩。

Sizzle is generally added to other libraries:

Sizzle通常会添加到其他库中:

A pure-JavaScript CSS selector engine designed to be easily dropped in to a host library.

纯JavaScript CSS选择器引擎,可轻松放入主机库。

jQuery is a much bigger library that does DOM manipulation, AJAX facades, and animations.

jQuery是一个更大的库,可以进行DOM操作,AJAX外观和动画。

Sizzle is a component of jQuery. jQuery uses it when no native DOM selectors are available, or when you use selectors the DOM doesn't support.

Sizzle是jQuery的一个组件。当没有可用的本机DOM选择器时,或者当您使用DOM不支持的选择器时,jQuery使用它。

Here is a perf illustrating the speed difference. (Sizzle is 34% faster in Chrome for these tests)

这是表示速度差异的性能。 (对于这些测试,Chrome的Sizzle快34%)

#2


8  

sizzle is completely included in jQuery. It's just a part of it, also developed by John Resig.

sizzle完全包含在jQuery中。它只是其中的一部分,也是由John Resig开发的。

If you only use selectors, import sizzlejs. But if you use other jQuery features, there is no reason to also use sizzle directly. Yes, it would be faster but cases where this gain is noticeable are very rare in a real application : there is no net gain if your code handles a click in 1 ms instead of 2 ms if your source is more complex.

如果您只使用选择器,请导入sizzlejs。但是如果你使用其他jQuery功能,没有理由直接使用sizzle。是的,它会更快但是这种增益明显的情况在实际应用中是非常罕见的:如果您的代码在1 ms内处理点击而不是2 ms(如果您的源更复杂)则没有净增益。

#3


4  

Sizzle.js is a JavaScript library that implements a "CSS selector engine designed to be easily dropped in to a host library." jQuery uses it internally for its CSS selection needs. If you wanted a CSS engine and had no need for all the other JavaScript benefits of jQuery, you could use Sizzle.js separately.

Sizzle.js是一个JavaScript库,它实现了一个“CSS选择器引擎,可以轻松地放入主机库中。” jQuery在内部使用它来满足CSS的选择需求。如果你想要一个CSS引擎并且不需要jQuery的所有其他JavaScript好处,你可以单独使用Sizzle.js。

#4


2  

jQuery uses Sizzle to select elements from the DOM. It then wraps this functionality with event handling, AJAX, DOM manipulation, animation and other features so it is a superset of the Sizzle functionality. One doesn't necessarily replace the other, but jQuery augments Sizzle.

jQuery使用Sizzle从DOM中选择元素。然后它通过事件处理,AJAX,DOM操作,动画和其他功能包装此功能,因此它是Sizzle功能的超集。一个不一定取代另一个,但jQuery增加了Sizzle。

#1


26  

Sizzle is much more lightweight than jQuery. jQuery is an entire DOM manipulation library and sizzle is just a selector engine. jQuery is 80kb gzipped and minified. Sizzle is 50kb uncompressed.

Sizzle比jQuery更轻量级。 jQuery是一个完整的DOM操作库,而sizzle只是一个选择器引擎。 jQuery是80kb gzip和minified。 Sizzle是50kb未压缩。

Sizzle is generally added to other libraries:

Sizzle通常会添加到其他库中:

A pure-JavaScript CSS selector engine designed to be easily dropped in to a host library.

纯JavaScript CSS选择器引擎,可轻松放入主机库。

jQuery is a much bigger library that does DOM manipulation, AJAX facades, and animations.

jQuery是一个更大的库,可以进行DOM操作,AJAX外观和动画。

Sizzle is a component of jQuery. jQuery uses it when no native DOM selectors are available, or when you use selectors the DOM doesn't support.

Sizzle是jQuery的一个组件。当没有可用的本机DOM选择器时,或者当您使用DOM不支持的选择器时,jQuery使用它。

Here is a perf illustrating the speed difference. (Sizzle is 34% faster in Chrome for these tests)

这是表示速度差异的性能。 (对于这些测试,Chrome的Sizzle快34%)

#2


8  

sizzle is completely included in jQuery. It's just a part of it, also developed by John Resig.

sizzle完全包含在jQuery中。它只是其中的一部分,也是由John Resig开发的。

If you only use selectors, import sizzlejs. But if you use other jQuery features, there is no reason to also use sizzle directly. Yes, it would be faster but cases where this gain is noticeable are very rare in a real application : there is no net gain if your code handles a click in 1 ms instead of 2 ms if your source is more complex.

如果您只使用选择器,请导入sizzlejs。但是如果你使用其他jQuery功能,没有理由直接使用sizzle。是的,它会更快但是这种增益明显的情况在实际应用中是非常罕见的:如果您的代码在1 ms内处理点击而不是2 ms(如果您的源更复杂)则没有净增益。

#3


4  

Sizzle.js is a JavaScript library that implements a "CSS selector engine designed to be easily dropped in to a host library." jQuery uses it internally for its CSS selection needs. If you wanted a CSS engine and had no need for all the other JavaScript benefits of jQuery, you could use Sizzle.js separately.

Sizzle.js是一个JavaScript库,它实现了一个“CSS选择器引擎,可以轻松地放入主机库中。” jQuery在内部使用它来满足CSS的选择需求。如果你想要一个CSS引擎并且不需要jQuery的所有其他JavaScript好处,你可以单独使用Sizzle.js。

#4


2  

jQuery uses Sizzle to select elements from the DOM. It then wraps this functionality with event handling, AJAX, DOM manipulation, animation and other features so it is a superset of the Sizzle functionality. One doesn't necessarily replace the other, but jQuery augments Sizzle.

jQuery使用Sizzle从DOM中选择元素。然后它通过事件处理,AJAX,DOM操作,动画和其他功能包装此功能,因此它是Sizzle功能的超集。一个不一定取代另一个,但jQuery增加了Sizzle。