Live data from Hacker News

You might not need jQuery

youmightnotneedjquery.com

81–90 of 360 posts

Re: You might not need jQuery

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

Define "modern"? IE8? Older Android browsers? How much compatibility are you willing to give up?

Re: You might not need jQuery

#82
post #11

> in truth, post-IE8, browsers are pretty easy to deal with on their own I totally agree, but not everyone lives in a post-IE8 world. It's as much as 10% of our traffic on some sites and several big clients use it.

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.

Re: You might not need jQuery

#84
post #35
post #7

Earlier quoted context omitted.

This is actually a great example of the purpose of the site. Since IE8, browsers have supported a native 'sizzle-style' element querying syntax: http://youmightnotneedjquery.com/#finding_elements IE9 and later also support a native each. You are correct however that you'd have to use Array.prototype.each.call, because the NodeList is not a real array.

Resig on document.querySelectorAll: http://ejohn.org/blog/thoughts-on-queryselectorall/ Good SO discussion on this topic: http://stackoverflow.com/questions/11503534/jquery-vs-docume...

It's still more complex, because you still have to iterate over it.

Re: You might not need jQuery

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

That's a great point - this is really awesome as a "learn the essence of what jQuery is doing for you!" and a little annoying as a "you don't need jQuery!".

Re: You might not need jQuery

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

We have a challenge in that so many of our web applications are built in a way that prevents us from performing analysis across technologies. For example, a modern rails app will possibly include haml, sass, coffeescript, and ruby along with the usual html, Javascript, css, etc., that are included in the various gems and plugins.

There are a lot of ways to skin this poor cat, but at this time they are generally manual and therefore unused. As a result, we try to solve dead code problems as if it is an entirely new challenge.

Dynamic code, and especially code with insufficient test coverage, poses a particular challenge, but again, it is generally possible to instrument code to see if it is ever called by the application.

Re: You might not need jQuery

#87
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 think the question is, does your library need every function on that page? If so, just use jQuery. But do you just need one thing? Then maybe it's better to just make the one utility function rather than pull in all of jQuery.

Re: You might not need jQuery

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

  git fork jquery
  git branch "fix-performance-issue-at-"
  git commit ...
  git push

Re: You might not need jQuery

#89
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 answer to that is: generally not for IE 10 & above. Sometimes for IE9. Often for IE8.

Take a look at the caniuse tables for common functionality in JQuery:

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

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

http://caniuse.com/#feat=css-transitions

http://caniuse.com/#feat=getcomputedstyle

http://kangax.github.io/es5-compat-table/#Array.prototype.fo...

Post reply on HN