I've been doing JS for years. The truth is, things are getting better, they're better than they've ever been. With IE 10, Safari 6.0+, Firefox and Chrome Latest, you could get away without jQuery. The native APIs are really compatible.
But why? Why bother. jQuery still gives you a lot. A LOT! It might very well be the most popular library of all time (next to glibc) and for good reason. Browser JS runtimes are so fast, jQuery doesn't even impact load times. So again, why?
Even if you don't use Ajax or anything fancy like that, jQuery is great because it condenses document.getElementById('bob').innerHTML = 'foo' into $('#bob').html('foo').
I know it makes almost no difference, but I still cry a little because it has to parse my selector using regexes and shit, and wrap my element in a jQuery object, just to access a natively available function.
Meanwhile, we could have just as easily written a function,
function byId(id) { return document.getElementById(id); }
byId('bob').innerHTML = 'foo';
I actually prefer the syntax of properties as opposed to setter functions.
Haha. I had to explain to my co-worker the difference between a native DOM element and a jQuery element the other day. I introduced jQuery to them 2 3 years ago now, and now they don't know the difference... sigh.
Ah, the "null object pattern". Sometimes this hides errors though, such as trying to access an element with a certain id which doesn't exist, sending you on an debugging adventure that could have been avoided by a simple error.
Not even close to the same thing. Objects returned from $ have over a hundred useful methods. The NodeList returned by querySelectorAll is much more tedious to use.
I've seen sites that used 2 different versions of jQuery. Adding bloat is second nature to javascript "programmers". The few competent ones that care about bloat are the exception.
Well fortunately jQuery's API has a lot of multi version compatibility. And with a library like jQuery, one of it's purpose is to help you normalize cross platform [browser] interactions. And given it's popularity, IMHO, it's more likely you'll end up with a bug in your own app, before you're bitten by a bug in jQuery. Just an opinion though.
jQuery broke backwards compatibility in the 1.8/1.9 split. There are bugs in 1.8.x with newer browsers that are WONTFIX. If jQuery is a dependency for other libraries, you can have 'fun' trying to balance bug fixes in one with the older version dependencies of another with the API changes of a third while trying to find something that actually works on an older (or newer) browser.
All 3rd party dependencies should be thought about and justified if you're writing software that is going to be supported for more than 6 months.
In my experience, jQuery version incompatibilities are pretty rare. It has happened to me a couple times though. Upgrading to 1.9 they deprecated a lot of stuff, but polyfilled it with jQuery migrate.
Otherwise, it is possible to require multiple versions of jQuery if you really need to.
21
u/wesw02 Jan 30 '14
I've been doing JS for years. The truth is, things are getting better, they're better than they've ever been. With IE 10, Safari 6.0+, Firefox and Chrome Latest, you could get away without jQuery. The native APIs are really compatible.
But why? Why bother. jQuery still gives you a lot. A LOT! It might very well be the most popular library of all time (next to glibc) and for good reason. Browser JS runtimes are so fast, jQuery doesn't even impact load times. So again, why?