Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am trying to develop a single-page web application. I was wondering how big the disadvantages of using jQuery are.

I have been told that it makes the application slower, but, as I have seen here, there are only 150ms at every 500 consecutive selections, which seems to me impossible to notice by a user.

Others say, that with every jQuery selection, the browser will save jQuery objects in its cache, instead of DOM elements, making the cache bigger, resulting a bigger memory consumption and therefore making the application run slower. Is this true? (I have no idea how the browser's cache is working.)

Is jQuery really slowing down such an application? (By this, I mean if the user will ever notice the use of this framework or not.)

share|improve this question

closed as not a real question by Joel Etherton, gnat, Jarrod Roberson, Walter, Jim G. May 15 '12 at 3:17

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

Slower than what? Standard Javascript? Loading the page each time? Something else? What browsers do you support? What would you expect your users' minimum environment to be? –  pdr May 14 '12 at 12:19

2 Answers 2

up vote 14 down vote accepted

Well, check out by yourself: http://jsperf.com/gebi-vs-sizzle/2

jQuery slows down your application. A lot.

However, as you can see on this jsperf, the operation, even though it's 10x slower than vanilla javascript, it can still run over 400k operations per second.

Except if you're programming for mobile browsers, the performance loss will not be noticeable. And still, it depends on the kind of mobile (recent ones (1-2 y.o.) are really fine).

Most of the time, the bottleneck is not especially in jQuery, but in a bad use of jQuery, or javascript in general. When you use selectors like $(this).attr('id') instead of this.id, or selectors like $('.class > div + p:last-child').find('a').attr('id'), you're doing it wrong. When you're doing a DOM operation in a loop, most of the time you're doing it wrong, and it can be done in a better/more efficient way.

Program wisely, and you will be fine with jQuery most of the time.

share|improve this answer
Program wisely, and you will be fine with jQuery most of the time. +1 for that, however that should be in bold H1 with stars and dancing unicorns around it. –  rlemon May 14 '12 at 12:58
Alright, edited :p –  Florian Margaine May 14 '12 at 12:58
where are my unicorns? –  rlemon May 14 '12 at 12:59
+1 For even though it's 10x slower than vanilla javascript, it can still run over 400k operations per second. this often gets ignored in the chat :P –  Esailija May 14 '12 at 13:29
I concur. . . . –  Andy E May 14 '12 at 13:37

speed is relative; bugs are not!

jQuery is still extremely fast compared to human perception, bugs are bugs no matter how fast or slowly they surface themselves.

The reason jQuery exists is to elimination the duplication of effort that every JavaScript programmer was creating doing the things jQuery does, but each person was creating their own buggy and slower version of jQuery.

If jQuery reduces your effort and increases maintainability then use it. If certain things aren't performant enough after profiling; there is nothing stopping you from using straight JavaScript in those specific places.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.