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?)

futlib
  • 2,107
  • 3
  • 21
  • 26
  • 1
    Related: https://gist.github.com/1455456 ;) For XHR, I'd suggest you [this helper](https://github.com/Ralt/dmcmag-requirejs/blob/master/src/helpers/xhr.js). It doesn't answer you, but you get my point. – Florian Margaine Jun 21 '12 at 09:40

3 Answers3

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).

Oliver Weiler
  • 2,448
  • 19
  • 28
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

Florian Margaine
  • 6,791
  • 3
  • 33
  • 46
  • 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 Jun 21 '12 at 10:13
  • I don't find it harder to read, I find it more explicit. Matter of preference. – Florian Margaine Jun 21 '12 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. – Michael Durrant Jun 21 '12 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. – Florian Margaine Jun 21 '12 at 12:48
  • "Everybody knows that" - hmm, this seems to be discouraging counter-arguments. jQuery has lots of value: https://decadecity.net/talks/what-has-jquery-ever-done-for-us – elias Jun 21 '15 at 05:17
  • @elias and I am mentioning its value later on. Did you read the answer? – Florian Margaine Jun 21 '15 at 09:13
  • I did, and your only mention was supporting legacy browsers -- there is more than that (event handling, AJAX, utility functions, selector extensions), all things that will avoid bugs and ease maintainability. Point is, not using it is costly, you should have very good reasons to justify doing it. – elias Jun 21 '15 at 13:35
  • The points you mention are easy to do when not having to support legacy browsers. – Florian Margaine Jun 21 '15 at 13:55
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.

elias
  • 162
  • 5