Live data from Hacker News

You might not need jQuery

youmightnotneedjquery.com

71–80 of 360 posts

Re: You might not need jQuery

#72
post #52
post #21

You had me convinced until I scrolled down to read the code examples and realized why I actually do need jQuery. If its between adding yet another collection of utility functions to approximate the functionality jQuery would give me vs just adding jQuery. I'd rather go with jQuery.

I had exactly such a collection of DOM utility functions and was glad to give it up. For example, rooting around in element.className was never very enjoyable. Also, the site does not show handling null cases which adds more code.

You have element.classList on all modern browsers now:

http://caniuse.com/#search=classList

It used to be that the first thing I'd reach for when building a prototype was JQuery off a CDN, but now I find that more and more of what I use JQuery for is built into the browser, and in my last few prototypes I've just stopped including it at all because I don't need it.

Re: You might not need jQuery

#74
post #68
post #57

No, please no. If size is an issue for some reason or you want to have no dependencies you can use something like http://zeptojs.com/ and just embed everything in one minified file. If you do things right only the functions you are actually using will get placed in there as well. Do not reinvent the wheel to solve problems that can't be solved in much cleaner and nicer ways. Managing dependencies can be annoying, but…

Fantastic point. Abstractions can be dangerous because they often aren't developed right. But that isn't the case here. When something like jQuery comes along, hiding so many gory details, and has been tested to death both in development and in production use all over the world, we are all better off because we remove so much failure surface area from our code.

The question is, how many of those gory details still exist in modern browsers? There's not much to test if you're just calling el.classList.add().

Re: You might not need jQuery

#75
post #57

No, please no. If size is an issue for some reason or you want to have no dependencies you can use something like http://zeptojs.com/ and just embed everything in one minified file. If you do things right only the functions you are actually using will get placed in there as well. Do not reinvent the wheel to solve problems that can't be solved in much cleaner and nicer ways. Managing dependencies can be annoying, but…

You don't need an abstraction to do something that's natively implemented on your platform.

Re: You might not need jQuery

#76
I would still stick with jQuery because it lets me achieve more by writing less. Out of many things, just see triggering custom events. It'd be horrible if I'll have to write that piece of code again and again and make sure it's bug-free. And if I contain that long logic into a function for re-use, and use this approach for everything listed on the page, I'll end up writing my own library that I'll be including in each of my projects. Wait, why don't I use jQuery instead which is battle proven and better tested than my library ever will be?

Re: You might not need jQuery

#77
Some of the examples are flawed. The ajax one for IE8+ is a big red flag, it's not as easy as that.

However, operating in the world without jQuery is scary for a new developer. I think it has its utility.

Note: I tend to prefer not to use jQuery, especially with AngularJS around. YMMV

Re: You might not need jQuery

#78
post #67
post #48

Greenspun's Tenth, updated for 2014: "Any sufficiently complicated website contains an ad-hoc, informally-specified bug-ridden slow implementation of half of jQuery" I understand the visceral opposition, but once you start writing a fallback to support some browser (something to support IE or FF or Safari or Chrome ...) you might as well use the battle-tested solution (and write your own thing if you find performance…

The question at hand is, are fallbacks necessary anymore for the browsers we are targeting today?

And the followup is, when do you remove fallbacks from your code? Every time I think I should remove something I end up thinking, "well, it still works just fine, does it really matter if it stays for a little longer?"
Post reply on HN