Live data from Hacker News

You might not need jQuery

youmightnotneedjquery.com

161–170 of 360 posts

Re: You might not need jQuery

#161
post #8

Earlier quoted context omitted.

It sounds like you're looking for the querySelector and querySelectorAll methods: https://developer.mozilla.org/en-US/docs/Web/API/Document.qu...

querySelector and querySelectorAll could have been pretty great, but they suffer from some serious problems as they ended up spec'd. The one I hate most is that qSA returns Yet Another JavaScript Collection That Is A Lot Like An Array But Isn't An Array And Therefore Doesn't Have Any Of The Nice Methods(TM). Yes, you're going to have to iterate over the thing using an index in a loop. There's others: http://ejohn.org…

Elements is supposed to fix this:

http://dom.spec.whatwg.org/#elements

But AFAICT isn't implemented anywhere, which makes it not that useful. Perhaps a polyfill could be done.

Re: You might not need jQuery

#162
post #107

I recently did a project that didn't use jQuery in order to keep my code smaller. It was an embedded 3rd-party widget, so keeping the code as small as possible was a key requirement. The code I wrote supports down to IE7, but IE7 wasn't really the biggest issue. The real problem with not using jQuery is that all of the collective knowledge we have about browser inconsistencies is encapsulated in jQuery. When you run…

http://caniuse.com/

Re: You might not need jQuery

#163
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…

It's better if libraries don't just assume jQuery is everywhere, because I suspect those days are ending. Apps built on newer front-end frameworks like Angular and React might not need it, for example. As a library author it's becoming more important to think case-by-case -- use raw JS if you just have some simple selections or XHRs, or use Zepto/etc if that covers you, and only depend on jQuery if you really need it…

> Apps built on newer front-end frameworks like Angular and React might not need it, for example.

Well, Angular has jQuery (lite) built in.

Re: You might not need jQuery

#164

Earlier quoted context omitted.

That's why it's called You_Might_NotNeedJQuery. ;)

If you are developing a library, then your users _Might_ need to support old browsers and _Might_ need jQuery.

lots of js libs are for things like webgl that already dictate a recent browser.

Re: You might not need jQuery

#165

Earlier quoted context omitted.

Nope, I didn't hear anything further on it. Still seems like an interesting event to me, though finding time might be hard. (FWIW, we do similar things within my employer all the time.)

That's too bad. But as with all things it takes time and organization in addition to some willing victims. "Similar things" as in hackathons for fun, or hackathons structured to test out different approaches and tech?

Hackathons (really, prototypes) structured to test out different approaches.

Re: You might not need jQuery

#166
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…

[deleted]

Re: You might not need jQuery

#167
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…

I believe the point is that many libraries use about 1% of jQuery. That hardly justifies pulling in the entire thing. A personal anecdote: I recently un-jQueried a little piece of code and ended up with only a couple lines of extra code. Certain parts of jQuery are heavenly and well worth it, but really basic usage doesn't actually save that much. $("#something") instead of document.getElementById("something") is not…

> $("#something") instead of document.getElementById("something")

or even just document.querySelectorAll("#something")

Re: You might not need jQuery

#168
post #135
post #61

Earlier quoted context omitted.

You have it a bit backwards, IE8 doesn't include JSON support when you are in quirks mode, which no modern application should ever be in.

should is the most important word in that sentence : )

No, quirks mode is triggered by the developer not including a doctype. If you include a properly formatted doctype, you will have JSON support in IE 8.

Re: You might not need jQuery

#169

Earlier quoted context omitted.

And requires IE 9+ which rules it out for a lot of people...

Actually, no. IE8 supports it. http://caniuse.com/queryselector

IE8 is limited to the old CSS selectors so basically it sucks and doesn't really support it.

Re: You might not need jQuery

#170
post #52

Earlier quoted context omitted.

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.

Except Android 2.3 and below.

Compatibility issues still exist.

Post reply on HN