Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) jQuery and AJAX The Office Status Project Revisited

jQuery Performance.

What about jQuery performance? Thank you!

3 Answers

Kevin Korte
Kevin Korte
28,148 Points

I would imagine that JS might be a little faster. Well written JS anyway. Personally, I use and would use jQuery. It just makes life so much simpler. There are many other factors that go into jQuery's performance, especially on ajax calls. I personally use jQuery for that stuff.

If you write it in jQuery, and find yourself having performance issues using your browsers dev tools, and can pinpoint those problems to the use of jQuery, than I might consider writing that in JavaScript. But I personally haven't had to cross that bridge just yet.

That's just me personally, my feelings about it, and what I've done to this point. It's opinion, subject to agree or disagree. This is a debate that has been argued about a lot on the interwebs.

Ivan Burda
Ivan Burda
10,897 Points

Hi Kevin! Thank you for your opinion and for the comment on the functionality of JQuery on a PC with disabled JS as well. Have a great day! Ivan

Nicolas Wolf
Nicolas Wolf
11,607 Points

Since jQuery is a 3rd party library, it won't be able to run at "native" speeds like your plain javascript will. To be completely honest though, jQuery wasn't designed with application performance in mind. jQuery has grown on the philosophy of writing less to accomplish more. More often than not, you see jQuery excel most on the front end.

This video actually shows a good example of when you should probably not use jQuery: the $.each() method. The standard "for" loop is a better choice for your algorithms, as it runs much more efficiently. Granted, you won't see the evidence of that so much in an array as small as the ones we're using here, but if you had to perform a lot of quick lookups, run through a 2-dimensional array, or do heavy math equations, you'd notice the difference, and so would your users.

Not to be one-sided, there are two benefits I can think of for using $.each(), rather than "for". First off, you don't have to worry about scope issues, since you're essentially passing everything in to a function. Also, like all things jQuery,an $.each() method can help minimize your code, and depending on the implementation, can make your code a little more elegant and readable.

Ultimately, it's good to know there's an alternative to the "for" loop, and if you're sticking to the front end, or smaller applications, you'll likely not notice a difference between the two.

jQuery is filled with random alternatives to normal syntax. Keep an eye out for these and always as yourself what your program's priorities are. It may be better suited to the standard, long-form javascript.

Ivan Burda
Ivan Burda
10,897 Points

What do you mean, Hernán?

I mean for example: is it better to make an Ajax request using Jquery than javascript? In terms of performance of course... I will of course write more code using only js, but will it run faster for the user of my app?

Ivan Burda
Ivan Burda
10,897 Points

As I am new to JQuery and Javascript, we will probably need to wait for somebody more experience to answer this question. However, from what I understand, it is always better to use JQuery just in case JS support is disabled on the visitor's PC. Speaking about the performance, I have managed to find an answer here but it is just an opinion of somebody we do not know: http://stackoverflow.com/questions/18418529/jquery-speed-vs-javascript-speed

Really useful! Thank you! Let's wait then if someone else can also help :)

Kevin Korte
Kevin Korte
28,148 Points

Ivan Burda if JS support is disabled on the visitor's computer, jQuery won't help at all. It's still "Javascript", and it's still disabled in this case.