JQuery 速度 vs javascript 速度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18418529/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 11:50:22  来源:igfitidea点击:

JQuery speed vs javascript speed

javascriptjquery

提问by THE AMAZING

I know Jquery is just a library of javascript.

我知道 Jquery 只是一个 javascript 库。

is Jquery animation and events slower then javascript? If so, how much slower.

Jquery 动画和事件比 javascript 慢吗?如果是这样,慢多少。

i am trying to decide if i should rewrite my site in native javascript.

我正在决定是否应该用原生 javascript 重写我的网站。

回答by Hless

jQuery in terms of speed is quite fast for modern browsers on modern computers. So is pure JavaScript. Both run drastically slower on older browsers and machines.

jQuery 在速度方面对于现代计算机上的现代浏览器来说非常快。纯 JavaScript 也是如此。两者在较旧的浏览器和机器上的运行速度都显着变慢。

Pure Javascript to access the DOM can be faster as you can cut the overhead that jQuery has on this. However it doesn't always have to be faster as you could write some major mistakes that slow things down again. jQuery on the other hand has been battle tested over the past few years and is proven to be performant.

纯 Javascript 访问 DOM 可以更快,因为您可以减少 jQuery 在这方面的开销。但是,它并不总是必须更快,因为您可能会写一些重大错误,从而再次减慢速度。另一方面,jQuery 在过去几年中经过了实战测试,并被证明是高性能的。

Another thing is, jQuery wasn't specifically designed with mobile devices in mind. Events like clickcause a delay due to this fact (~300ms). jQuerys animations are also quite slow on the average mobile device because the way they are written makes them CPU bound, an average mobile device doesn't have alot of CPU power. A way around this is by using hardware accelerated CSS animations.

另一件事是,jQuery 并不是专门为移动设备设计的。click由于这个事实(~300ms),诸如此类的事件会导致延迟。jQuery 动画在普通移动设备上也很慢,因为它们的编写方式使它们受 CPU 限制,普通移动设备没有很多 CPU 能力。一种解决方法是使用硬件加速的 CSS 动画。