Live data from Hacker News

You might not need jQuery

youmightnotneedjquery.com

171–180 of 360 posts

Re: You might not need jQuery

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

For me jquery is all about events. Making sure I get the event tree bubbling in the correct way across the entire universe of browsers and all its data being normalized is such a time saver. Even their support isn't perfect, but I'm sure its way better than any other event library out there in terms of breadth and depth of testing. The selectors bit is a nice to have, but that is getting easier since its inclusion in dom itself.

Since I code mostly in clojurescript in my home hours any functional idioms from jQuery I no longer use. A long time ago jresig joked about making an oo form of jQuery. It's not that funny now, as it might be slightly easier to wrap an object based lib for all the various compile down to js languages (typescript, coffeescript, clojurescript, scalajs, etc)

Re: You might not need jQuery

#172
post #133

Earlier quoted context omitted.

Size really is issue when dealing with mobile devices. Even from disk cache each KB increases startuptime by about 1ms (and jquery 2 is ~32kb minified, for Also, last time I checked jquery uses "querySelectorAll" for that fancy $("selector") syntax, which is slow as hell with every possible browser compared to "getElementBy*". This might not be issue with desktop machines, but you will probably lose most of your mobi…

> Also, last time I checked jquery uses "querySelectorAll" for that fancy $("selector") syntax, which is slow as hell with every possible browser compared to "getElementBy". I seriously doubt you ever "checked". You would know that jQuery's selector engine (Sizzle) is optimized and uses getElementBy* when it can. You would also know that every browser has bugs in querySelectorAll, and jQuery's selector engine detects…

How complicated your query have to be to run into these QSA bugs? Don't forget that you are paying a very high performance cost for compatibility. I mean, how many people are still on Chrome 21 and Firefox 3.5?

Re: You might not need jQuery

#173
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?

Oh I see. Yeah you can just include a badge at the bottom right "Best used/viewed on Mac Firefox or Chrome".

For anyone else, just use jQuery.

Re: You might not need jQuery

#174
post #112

Earlier quoted context omitted.

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…

document.querySelectorAll() uses the same kind of syntax for selectors as jQuery.

and support only a limited subset of the selectors jQuery supports.

Re: You might not need jQuery

#175
post #74
post #68

Earlier quoted context omitted.

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().

And style.display='block' for jQuery.show() does not work with 's (which need 'inline-block') and rules which have an !important clause in the CSS (which need to first set the display to empty string and then set it again).

Re: You might not need jQuery

#176
post #74

Earlier quoted context omitted.

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().

More to test than you thought. That just broke more than 20% of the Android installed base, since Android 2.3 doesn't work with classList.

A classList polyfill is like 500b compressed. No need to blow a non-existent problem out of proportion.

https://github.com/remy/polyfills/blob/master/classList.js

Re: You might not need jQuery

#178
I think many commenters are misunderstanding the main idea here. This page makes a strong case if you're just using jQuery for a few things in your site. I can see people complaining "why would I write all that code again? if jQuery offers a beautiful API?" if you're just using jQuery to do a few simple things (Which I've seen all over the place among peers) then why not just write the native version? it's only a few lines and you're saving a whole library in your load process

Re: You might not need jQuery

#179

Earlier quoted context omitted.

Its el.hidden = true; in modern browsers

I'm curious - is this spec'd anywhere? I just tried it in Chrome and it works great, but I couldn't find it in any of the specs for Element or Node.

The best I found

http://www.whatwg.org/specs/web-apps/current-work/multipage/...

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_att...

Post reply on HN