Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

1–10 of 201 posts

Re: You Don't Need JQuery

#3
Every time I try to build something without jQuery, I regret it.

Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements.

No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically generated DOM objects? Write your own event bubbling library. Want to create custom events/handlers? Ditto. Promises, .serialize(), .extend(), etc. might all be simple to write your own version, but when you realize you've reimplemented 50% of jQuery to avoid using jQuery, you feel like an idiot. [Source: I do this every 3 years]

Life is too short to not use jQuery.

Re: You Don't Need JQuery

#4
Still reading through but it mentions, IE7 when, as I've found out recently, going to a 2.x jQuery release will break IE8 functionality which is still used within organizations either as the actual browser or through compatibility mode. I didn't care for the format of the page but do like the author's tone and points so far.

I think a lot of the issues people have with jQuery is that (as the article mentions) it's become synonymous with Javascript and abstracts so many things that many people using it don't understand the underlying framework and functions. That and why include more resources if you don't really need to.

Re: You Don't Need JQuery

#6

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

Agreed 1000%

Re: You Don't Need JQuery

#7
You can basically sum up this entire rather ridiculous site with "Yes, you don't need jQuery, you can just use the built-in methods, but using jQuery is generally more pleasant, more consistent, and involves less typing". One particularly egregious example from the site:

  $('#foo').removeClass('bold');
vs.

  document.getElementById('foo').className = 
      document.getElementById('foo').className.replace(/^bold$/, '');
The author summarises this, helpfully: "As usual, more characters, but still easy without jQuery."

Of course, if you were doing that remove class operation quite often, rather than writing all that code out each time, you might wrap it up in a helper method, and maybe you'd call it, I don't know, "removeClass" or something; perhaps if you were doing a whole bunch of DOM operations you might create little helper methods for each one, again to save you some typing. Pretty quickly you might end up with a little library of helper methods... and, of course, being a wonderful programmer who never makes mistakes, I'm sure that little library would be every bit as optimised, reliable, and correct as a battle-tested library used on hundreds of thousands of web sites.

Re: You Don't Need JQuery

#8

Every time I try to build something without jQuery, I regret it. Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements. No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically gene…

Yep. Use the built in browser methods? For which browser?!? All of them? I have to support some enterprise guys on IE8, sometimes I'm lucky to have them on IE9.

Life isn't always a hipster website where people can get lunch delivered on their phone or whatever. Things like jQuery are fine.

Re: You Don't Need JQuery

#9
It's something you see a lot of, especially from non-frontend developers that don't really think twice about downloading an extra 80-90kb of JavaScript. I do find the support for events in JQuery quite convenient, especially for projects that still require IE8 support. Although if that's all you're using it for, there are probably better ways.

Re: You Don't Need JQuery

#10
The AJAX examples fall a little flat. Yes, .ajax is a wrapper, and it was written because the API for XMLHTTPRequest is needlessly complicated and verbose.

If you're developing a single page application, you only load jquery once, then do the rest with AJAX calls for JSON and assets. It's worth the <100 KB on initial page load, at least for the projects I've worked on.

Post reply on HN