Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

101–110 of 201 posts

Re: You Don't Need JQuery

#101
post #98
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…

Actually since forever, you don't need to use document.getElementById("x") in any case. You just by putting the id to the element, it is already available to you referencing it by such id. So this: document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); Can become to this: foo.classList.remove("x"); And is miles away more performant than slow jQuery.

That won't work on Android 2.x, which doesn't support `.classList`. Performance isn't even an issue here since changing classes will cause a reapply-styles and layout.

Re: You Don't Need JQuery

#102
post #54
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…

also it hides the discrepancies between the various browsers

This is exactly the point. I don't mind the extra typing in those first few examples because jQuery is mysterious and it's nice to cut through the mystery. However, I don't want to have to fill my code with conditional logic based on the user's browser - that's lame.

The real value of this site is not what it says, but rather a reminder that jQuery is an abstraction and is made of code rather than magick.

Re: You Don't Need JQuery

#103

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…

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 be considered legacy code as soon as next week’s trendy framework arrives, leaving you with a maintenance headache for as long as your project lasts after that?

Doing the simple, effective thing is just crazy talk, I tell you.

Re: You Don't Need JQuery

#105
post #98

Earlier quoted context omitted.

Actually since forever, you don't need to use document.getElementById("x") in any case. You just by putting the id to the element, it is already available to you referencing it by such id. So this: document.getElementById('foo').className = document.getElementById('foo').className.replace(/^bold$/, ''); Can become to this: foo.classList.remove("x"); And is miles away more performant than slow jQuery.

That won't work on Android 2.x, which doesn't support `.classList`. Performance isn't even an issue here since changing classes will cause a reapply-styles and layout.

I care as much for Android 2.x as ie below 10.

Re: You Don't Need JQuery

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

You're aware of jQuery custom builds? Leave out what you don't use. It's in the README file.

Re: You Don't Need JQuery

#107

Earlier quoted context omitted.

and slowing down your website

jQuery is usually cached in your browser because of how common it is. From what I understand, the slowing is negligible. Part of a developer's role is to mitigate site performance with the speed of process. Inlining of critical CSS is one way to balance out initial page load, for example.

This is part myth. The chances your site has the same version of jQuery that the visitor's browser cache is are pretty low. iirc, someone once said it was less than 5%.

Re: You Don't Need JQuery

#108
post #105

Earlier quoted context omitted.

That won't work on Android 2.x, which doesn't support `.classList`. Performance isn't even an issue here since changing classes will cause a reapply-styles and layout.

I care as much for Android 2.x as ie below 10.

And probably 80% of our startup's revenue comes from banks stuck using IE8.

Re: You Don't Need JQuery

#109
This and you're good for selectors, but there's no right or wrong answer - use what works for you and the project.

$ = document.querySelector.bind(document); $$ = document.querySelectorAll.bind(document);

Re: You Don't Need JQuery

#110
post #35

Yeah, you don't need anything. You can write all your apps in vanilla JS, but if you feel like speeding up development...

and slowing down your website

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.
Post reply on HN