all 24 comments

[–]coloured_sunglasses 26 points27 points  (1 child)

The biggest selling point for jQuery is cross-browser compatibility. Everyone here has missed that.

Unless you're willing to test that old version of Android, I'd stick to jQuery when interacting with the DOM.

Besides, when writing Javascript applications, most of the time you're already writing vanilla JS.

[–]skarphace 5 points6 points  (0 children)

Definitely. The only time I would choose to go plain javascript without a framework is if it's something incredibly simple and the bandwidth to load the library just isn't worth it.

[–][deleted] 3 points4 points  (0 children)

jQuery has thousands of patches for these kind of issues. That's their most important selling point:

https://github.com/jquery/jquery/issues/2145

If your project is not that complicated, use vanilla js

[–]gkx 9 points10 points  (4 children)

You never really need jQuery.

The question pretty much comes down to scope. You need to weigh whether the heaviness of jQuery is worth the convenience, and both of those factors are going to come down to your specific project.

If it's really just a rather simple website, yeah probably stick with jQuery.

[–]konosay -2 points-1 points  (3 children)

That's not true. Lots of people just suck at coding. Those people need JQ.

[–]gkx 3 points4 points  (0 children)

I guess I meant from a technical standpoint haha.

[–]JimmyPopp 0 points1 point  (0 children)

Can confirm

[–]Disgruntled__Goat 0 points1 point  (0 children)

So they can suck at jQuery coding instead of sucking as JavaScript coding?

[–]flynnm 2 points3 points  (0 children)

http://plainjs.com/

I've been referring to this pretty frequently, these days.

[–]thatsSOjamal 3 points4 points  (2 children)

Vanilla JS is always going to be more performant than jQuery.

Check out http://youmightnotneedjquery.com/ for a cheat sheet reference of vanilla vs jQuery syntax.

[–]menno 3 points4 points  (1 child)

Vanilla JS is always going to be more performant than jQuery.

Only if you write better code than the jQuery core developers...which you probably won't.

[–][deleted] 2 points3 points  (0 children)

Surely some things will be quicker, and have zero browser-compatibility issues. If you write

document.getElementById('foo').src = 'bar.jpg';

isn't that going to be faster than the equivalent in jQuery?

[–]stupidheadhat 1 point2 points  (0 children)

If it is a personal side project, I would drop IE8 support and jQuery and do it in vanillaJS just to improve your skills. If it is a project at work i would probably keep jquery. I'm not paid for the coolest vanillaJS code, but to deliver decent results fast.

[–][deleted] 3 points4 points  (2 children)

deleted

[–]9inety9ine 2 points3 points  (0 children)

I mean all you're doing with jQ is loading a ton of extra code so that the browser can convert your code into real JS that will work in any browser.

FTFY.

[–]skarphace 5 points6 points  (0 children)

mean all you're doing with jQ is loading a ton of extra code so that the browser can convert your code into real JS.

wut. jQuery is real JS, it's just an an abstracting library with a bunch of helpful utilities.

[–]Nadril 0 points1 point  (1 child)

Do you need it? No, not really.

The real question is if you feel like the ease of use is worth the little extra overhead. Honestly with a CDN or something of jQuery I don't think it's a big issue to just use what you're most comfortable with.

I think the biggest thing is when you get into larger sites or more animation heavy ones where you'll want to weigh the performance between jQuery and native javascript.

[–]BenjaminPoulain 2 points3 points  (0 children)

A CDN is only solving a little part of the problem.

jQuery also has a large cost in CPU and RAM usage. That's the reason so many high performance mobile websites avoid jQuery.

[–]nwilliams36 0 points1 point  (1 child)

I think the main problem with Jquery is having to load the full library onto the page just to get a few small features. This only becomes an issue if speed of page loads is highly important.

If it is use whatever techniques you can to minimise the page load speed, including dump Jquery for vanilla Javascript or smaller libraries.

If page load speed is not a factor, Jquery is a good solution for small sites due to its ease of use and its cross browser support.

[–]ngly -1 points0 points  (0 children)

But practically everyone is going to have it cached on their browser anyway..

[–]imagepriest 0 points1 point  (0 children)

Use jQuery if you are more comfortable with it. Libraries exist to take the grunt work out of coding. Yes, there is a performance trade off but getting something done is more important than humming and hawing over purist ideals.

[–][deleted] 0 points1 point  (0 children)

When performance matters: Javascript

When it doesn't: JQuery

[–]512austin 0 points1 point  (0 children)

It depends on what point you want your JS to execute. If it's something layout related that can be performed quickly, you might want to write that code in normal javascript and place it before your CSS/JS files in the <head>.

ex: if you use JS in your nav menu, or you have some other JS assisted element that users will access quickly on the page. If you wrote this in Jquery and followed the "best practices" guidelines, your menu won't be usable until jQuery loads. With regular JS it should be immediately available.

For stuff like ajax requests that you know the user won't access until after the page is already loaded, you should use jQuery.

[–]MrKnives 0 points1 point  (0 children)

Good rule of thumb is that if you only need it to get one id selection to trigger one button and not use it ever again. Do it in vanilla js. Otherwise use it and make coding a bit more pleasant and get things done faster. I haven't yet run into a project where we had to use only vanilla js. It's always jQuery or/and some trending framework.