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

时间:2021-10-10 16:45:41

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


25  

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的压缩和缩小。嘶嘶声是50 kb未压缩的。

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不支持。

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

这里有一个关于速度差异的说明。(在这些测试中,Sizzle比Chrome快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毫秒而不是2毫秒,如果您的源代码更加复杂,那么就没有任何净收益。

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

嘶嘶声。js是一个JavaScript库,它实现了一个“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增强版仍然很流行。

#1


25  

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的压缩和缩小。嘶嘶声是50 kb未压缩的。

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不支持。

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

这里有一个关于速度差异的说明。(在这些测试中,Sizzle比Chrome快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毫秒而不是2毫秒,如果您的源代码更加复杂,那么就没有任何净收益。

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

嘶嘶声。js是一个JavaScript库,它实现了一个“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增强版仍然很流行。