18

I know Jquery is just a library of javascript.

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

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

THE AMAZING
  • 1,496
  • 2
  • 16
  • 38
  • Do you have a performance problem that you urge to rewrite your site like this? jQuery is just a JavaScript library, sure - jQuery objects are slower than using native DOM methods directly, but most of the time the performance does not really matter that much. – Benjamin Gruenbaum Aug 24 '13 at 12:25
  • Consider other factors in addition to speed. Which browsers you need to support, how much longer it will take you to develop, etc – ryan Aug 24 '13 at 12:26
  • I need to support all web browsers, as i currently do. The development time is not an issue. My site is fairly large and causes computers that have crummy hardware to lag a bit. As well for safari users. – THE AMAZING Aug 24 '13 at 12:28
  • 2
    consider using css3 animations instead of javascript/jquery! – RienNeVaPlu͢s Aug 24 '13 at 12:29
  • IF you simlply talk about speed javascript is bound to be faster cos jQUery does nothing more than calling javascript functions internally. But the performance difference is not considerable, and with the advantages jQuery offers using it will make your life much simpler – Farhan Aug 24 '13 at 12:29
  • So maybe i should rewrite the jquery functions that are causing lag in javascript? – THE AMAZING Aug 24 '13 at 12:30
  • Have you identified your performance bottleneck(s)? I highly doubt that switching from jQuery to vanilla JS will gain you much in the way of a speed boost and will probably introduce more issues than it solves. If you want measured performance differences, visit http://jsperf.com/ and have a look at some of the jQuery vs. whatever tests. – André Dion Aug 24 '13 at 12:30
  • I am actually using css3 more then using javascript/jquery, the problem actually resides in threading and events mostly. The lag in that causes a lag graphically with other functions. – THE AMAZING Aug 24 '13 at 12:31
  • Your question makes no sense. Why do you think you're going to be able write the equivalent functions *better* than the entire jQuery community? You can't "rewrite" parts of jQuery to be faster, especially if you need to support "all web browsers", it's already pretty optimally written. – user229044 Aug 24 '13 at 12:37
  • @RichardGrant - You cannot do much about performance of a web site as you have no control over the hardware/OS/What else is running/Their network connection... I would plump for JQuery as you do not have to worry about the browser issue so much. As to using CSS3 it is worthwhile checking your server logs as to gain an understanding of what your web site users as using as a browser - you do not wish to alienate them if lots of them are using older browsers. – Ed Heal Aug 24 '13 at 12:40
  • most of my web users are using internet explorer and safari, which makes things hell for me ;/ but i know that the jquery community has spent tons of time developing their functions which is most def. useful but since jquery requires linking to a large script file, reading that file then looking up functions on each use this could be a delay i do not want. – THE AMAZING Aug 24 '13 at 12:59
  • @RichardGrant - version numbers are important. Besides when JQuery has figured out the browser/version number it sets up the framework in the correct manner. – Ed Heal Aug 24 '13 at 22:54
  • Why closed as off topic???? If you can close this off as 'off topic', then you can close anything as 'off topic' because this is right on topic with stackoverflow. –  May 08 '17 at 21:38

1 Answers1

32

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.

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.

Another thing is, jQuery wasn't specifically designed with mobile devices in mind. Events like click cause 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.

Hless
  • 3,326
  • 20
  • 22
  • 3
    Hm, a fun fact i never knew about jquery :) – THE AMAZING Aug 24 '13 at 12:35
  • 1
    In my opinion you should stick with jQuery. I don't think writing everything in pure JS is going to give you any noticable performance boost nowadays. I have written Mobile Sites that feel native using jQuery, just by using CSS animations instead. The rest of the framework is super fast in my experience. Also selectors & events and such are so much easier in jQuery as opposed to JS. – Hless Aug 24 '13 at 12:43
  • Okay, ill take your word for it. what about if i use selectors in variables in instead of typing the selector out everytime? Could that spread anything up? – THE AMAZING Aug 24 '13 at 12:49
  • I tend to do that, and I found another post on stack that says jQuery isn't caching selectors. So yes, that would help with performance. I also tend to use `selectorVar.find('.class')` to search in smaller areas of the DOM, instead of matching against the full DOM again. Post is here: http://stackoverflow.com/questions/291841/does-jquery-do-any-kind-of-caching-of-selectors – Hless Aug 24 '13 at 13:25
  • well then thats a good thing to keep in mind :) thank you all – THE AMAZING Aug 24 '13 at 21:40
  • Perhaps you should look at the JQuery source code, and think again. There is no evidence whatsoever that the people who created JQuery had any consideration for performance whatsoever. I wounder if you are confuzling the V8 engines magic tricks with JQueries... Hmmmm... –  May 08 '17 at 21:42
  • I'm not one for jQuery plugins, but jQuery transit is SO much better than jquery's `.animate`. –  Aug 12 '18 at 03:11