Live data from Hacker News

You might not need jQuery

youmightnotneedjquery.com

51–60 of 360 posts

Re: You might not need jQuery

#51
post #49

This be right on a purist level, but on every practical level there is little reason not to use [library of your choice]. If you're loading from the google/jQuery CDN (with suitable fallback, obvs.) you've got a good chance of a cache hit, and even if it misses it's a tiny one-off penalty. And ultimately, why not? jQuery works, has a wide base of users, etc. Sure your trivial Js might not need jQuery features now, bu…

i do Enterprise work & if we have jQuery in a page IBM dismisses our PMRs when we submit issues. So yeah I regularly include some simple cross-browser-normalizing js functions to use with the vendor-approved libs.

Also, jQuery is not trival to use in conjunction with other js libs (Dojo) as namespacing proponents claim. It's not like you just include both & they don't interfere. You have to follow a specific initialization pattern.

Re: You might not need jQuery

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

Re: You might not need jQuery

#53
The Bad:

The premise of the examples list seems a bit disingenuous.

Very few of these things take into account the full convenience of jQuery. It's much more than saving a couple lines of code or knowing the native way to accomplish the most basic version of a task. jQuery's real benefit is preserving simplicity as your needs grow more complex.

Right off the bat I feel like the getJSON[1] example is a bit simplistic. Almost anyone using ajax needs to serialize data, handle errors, prevent caching, etc. jQuery has thought about all this[2].

Don't get me wrong -- most of my work has been without jQuery, but that means I know exactly how much work it is.

The Good:

The format is a nice way to show people (who really don't know otherwise) the native JS plumbing.

"The number of people who don't know that jQuery != Javascript is too damn high". So to help combat that, I really appreciate the idea behind this site.

It's great to show side-by-side how jQuery isn't "magic", since many people seem to learn jQuery these days without even knowing the first thing about Javascript, but I just think it should be presented with a slightly different premise.

[1]: http://youmightnotneedjquery.com/#json -- side note, why did they set the handler after the `send`? It seems like that could cause problems if the result was returnable quickly, such as from cache, though I haven't tested it.

[2]: http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings

Re: You might not need jQuery

#55
post #32

So, uh, what will I gain by ditching jQuery? I will lose a beautiful API with a simple, terse and familiar syntax. I will have to work with an ugly, inconsistent and loquacious API, which has no guarantee of being cross-browser (or accounting for various browser quirks). And for what? I doubt 81 KB would make much difference to 99.9% of my visitors. As for performance -- it makes sense to rewrite bottlenecks in pure…

You lose dependency on a monolithic library which creates vertically-stacking dependencies and library conflicts. By ditching it, you gain the ability to construct your app out of loosely-bound components supported by independent developers.

Re: You might not need jQuery

#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 we all bite the bullet for a very good reason, because reusing solid well tested code is a good thing.

Re: You might not need jQuery

#59
post #53

The Bad: The premise of the examples list seems a bit disingenuous. Very few of these things take into account the full convenience of jQuery. It's much more than saving a couple lines of code or knowing the native way to accomplish the most basic version of a task. jQuery's real benefit is preserving simplicity as your needs grow more complex. Right off the bat I feel like the getJSON[1] example is a bit simplistic.…

right off the bat its wrong, IE8 doesn't include JSON support unless you're in strict mode.

Re: You might not need jQuery

#60
post #18

What? > $(' ').append($(el).clone()).html() vs > el.outerHTML Why not $(el)[0].outerHTML?

What if $(el).length === 0?

This check is required in both cases. el.outerHTML assumes that el is not NULL (which it could be as a result of getElementById, for example).
Post reply on HN