Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

121–130 of 201 posts

Re: You Don't Need JQuery

#121
post #37

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…

Yeah, the problem with jQuery is all that other stuff that nobody uses and backwards compatibility with browsers nobody supports. A "lite" jQuery with the same familiar API but a stripped-down featureset for higher performance and smaller size would be nice.

jquery 2.x removes support for those browsers at least.

Re: You Don't Need JQuery

#122

Earlier quoted context omitted.

Life is definitely too short to not be using npm, browserify and React! https://www.npmjs.com/package/browserify https://www.npmjs.com/package/react And then use just what modules you need. All the functionality of jQuery has already been ported to various modules. https://www.npmjs.com/package/extend https://www.npmjs.com/package/promise https://www.npmjs.com/package/serialize-form

Yes, why use a tried and tested tool that can be incorporated into your site and served efficiently with just a single extra line, when instead you could make building your site more complicated than compiling an entire Linux distribution from source, spend days choosing between a bunch of almost identical micro-libraries for every little thing you need to do, and lock yourself into a proprietary framework that will…

make building your site more complicated than compiling an entire Linux distribution from source

http://browserify.org/

Browserify is not at all complicated.

spend days choosing between a bunch of almost identical micro-libraries for every little thing you need to do

Just search npm and pick the one that is being used the most.

lock yourself into a proprietary framework that will be considered legacy code as soon as next week’s trendy framework arrives

The problems that npm and browserify solve are at the level of builds and package management. You could use any number of trendy frameworks and tools on top of this.

Re: You Don't Need JQuery

#123

Earlier quoted context omitted.

> Life is definitely too short to not be using npm, browserify and React! These are all cool things, but sometimes you want to simply make a web page without setting up node and npm and all that jazz. Think of it this way... jQuery is like getting a subset of the most common functions you get by using in browserify, but without requiring a build step!

This is about more than just a build process. jQuery's imperative DOM manipulation is a horrible way to manage state compared to React. These tools aren't just "cool things". They were designed to solve really pressing issues related to managing complexity in front-end web applications by eliminating global state in both the DOM or the JS runtime environment. They tend towards a more declarative and functional approa…

This reads like a parody.

Re: You Don't Need JQuery

#124
I disagree, jQuery is awesome, even for seasoned web developers. Of course you don't need it, but it makes life a lot easier when working with XHR, events, selectors, etc.

If you're worried about dependencies, you could just compile your released library with the Google Closure compile, and strip out everything you don't use. You could even set up a pipeline to produce two releases: one that has bits of jQuery embedded, and a smaller one that requires jQuery.

EDIT: Thanks to dmethvin [1], I just learned that you can also build your own jQuery [2] that only includes the modules you need.

[1] https://news.ycombinator.com/item?id=8760352 [2] https://github.com/jquery/jquery#modules

Re: You Don't Need JQuery

#125
The best thing about jQuery is that it abstracts away most of the browser-specific quirkiness for you. Using jQuery for that feature alone makes it worth using.

Re: You Don't Need JQuery

#126

Earlier quoted context omitted.

well that's the trade-off, isn't it? unless my app is speed-heavy, i'm not gonna spend the extra man-hours needed (that jquery saves me) so that website runs negligibly faster.

good luck ranking in google and explaining your self to your md when your major publishing site takes 20 seconds to load I wont mention any names but I know of two cases of this.

The jQuery library is 45k, half that if gzipped. If it's taking 20 seconds to load, your birds are too slow.[1]

[1] https://tools.ietf.org/html/rfc1149

Re: You Don't Need JQuery

#127

Earlier quoted context omitted.

well that's the trade-off, isn't it? unless my app is speed-heavy, i'm not gonna spend the extra man-hours needed (that jquery saves me) so that website runs negligibly faster.

good luck ranking in google and explaining your self to your md when your major publishing site takes 20 seconds to load I wont mention any names but I know of two cases of this.

if it takes 20 seconds to load, you have bigger problems than jquery.

Re: You Don't Need JQuery

#128
post #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 au…

Perhaps I'm being a bit dense (I've done prettymuch no front-end JavaScript), but since className gives a single string with class names separated by spaces[1], won't document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); fail if the element in question has more than one class? In that case, you'd need to get the className attribute, split it by spaces, do the repla…

You're right it will only work for one class. This is actually a perfect example of jQuery smoothing out the rough edges for you. I think the split method would work (provided you remember to split with \s instead of just space). It actually took me a while to come up with a regex replace that won't break in some corner cases ( I think)

    document.getElementById('foo').className = document.getElementById('foo').className.replace(/(\s|^)foo(\s|$)/, ' ');
\b is out because it matches - and would kill stuff like foo-bar.

Re: You Don't Need JQuery

#130
post #66

Earlier quoted context omitted.

I've only used jQuery once, for a client who insisted we use it, and it was the worst experience of my company's life. It only made us use bold on all our documents which proudly states, "No JQuery!".

Surely you can expand on this story. What made using jQuery so painful?

I'll try.

My client was mad I was trying to charge him an extra $6000 for the time I spend to get the stuff I write to work across different browsers and asked me to use jQuery instead.

Post reply on HN