9

I'm lately working on a few mobile web apps for Android (2.3+) and iOS (4+). Their browsers support most of ECMAScript5, which is very powerful, and I wanted to use language features where possible, resorting to jQuery only when I had to.

Turns out the only thing I use jQuery for is to have a shorter alternative for document.querySelectorAll. Might as well get rid of it.

If I only have to support modern WebKit browsers, is it a good idea to get rid of jQuery (and other general-purpose libraries)? They are a layer of indirection, after all.

(The apps don't have to make AJAX calls so far, I guess that's one thing that's going to get ugly. But is it worth keeping jQuery just for that?)

1

3 Answers 3

8

No, it doesn't make sense.

jQuery is a bloated library. Everybody knows that. And everybody uses it because it's one the rare cross-browser libraries out there that just work (note that I didn't say framework).

If you don't need support for legacy browsers, you don't need jQuery.

Small needs such as QSA shortcut or an XHR helper are thin. They are easily added through such objects.

Then, if you like its API, go for it. But it's not needed.

I can understand that some people prefer:

$( '.table' ).addClass( 'active' );

To (using By):

[].forEach.call( By.qsa( '.table' ), function( table ) {
    table.classList.add( 'active' );
} );

I find the second way more explicit, other will disagree. It's a matter of preference.

Also, if your code has any chance of being ported to legacy browsers later (or other non-webkit/sucky mobile browsers), use jQuery. It will reduce your headache later.

Related: https://softwareengineering.stackexchange.com/a/148536/42132

8
  • 3
    What if you have done this 25 times (not addClass x25 but there are a ton of other similar cases)? It gets harder and harder to read because there is just so much more code to be read.
    – Esailija
    Commented Jun 21, 2012 at 10:13
  • I don't find it harder to read, I find it more explicit. Matter of preference. Commented Jun 21, 2012 at 10:20
  • 3
    I feel that there are a lot of other reasons to use jQuery other than just support for legacy browsers. I disagree with the opinions of this answer which seem extremely subjective and based on preference rather than fact. Commented Jun 21, 2012 at 12:47
  • @MichaelDurrant yes, jQuery usage of its API is extremely subjective and based on preference. Which is what I said in this answer. Commented Jun 21, 2012 at 12:48
  • "Everybody knows that" - hmm, this seems to be discouraging counter-arguments. jQuery has lots of value: decadecity.net/talks/what-has-jquery-ever-done-for-us
    – elias
    Commented Jun 21, 2015 at 5:17
8

I think it's still worth using. jQuery effectively makes your code more compact and more readable, resulting in faster development and less maintenance (taking into account you have some experience with it).

If jQuery is too heavy-weight for you, you should give Zepto a try, which is kind of a light-weight alternative for jQuery (with a similar api).

0
0

I'd say, when you don't know what to do, just use jQuery.

jQuery has lots of value, handles edge-cases and avoid headaches for you: https://decadecity.net/talks/what-has-jquery-ever-done-for-us

Using jQuery is standing on the shoulders of giants.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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