Live data from Hacker News

You Don't Need JQuery

blog.garstasio.com

151–160 of 201 posts

Re: You Don't Need JQuery

#151

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…

You can "eat the cake and have it too" with something like this: http://microjs.com/ Basically you import everything you need and only what you need. Need extend? No prob: http://microjs.com/#extend - just pick one. And with browserify and npm literally everything you need to do to include a library in your project is a single command, so having to include "that many libraries" is not really a problem. I'm a huge fan…

Same. Between Micro JS, Vue.js and Browserify, I can craft the perfect tech stack with best-of-breed libraries, and come out with a much smaller, faster, and less janky site at the end of it. Oh, and being CommonJS modules via Browserify makes life pretty great, and my code maintainable and easy to follow!

Re: You Don't Need JQuery

#153

Earlier quoted context omitted.

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…

So, basically, you end up rewriting the glue code and plumbing, keeping track of twenty-eight security bulletins instead of one, and hoping that someone doesn't get a zero-day in a less used library that doesn't has much security attention paid to it. And that's fine, if writing a framework per project is something you have time for. But make no mistake -- you're writing a framework.

you end up rewriting the glue code and plumbing

I'm not sure what you mean. Can you give an example?

keeping track of twenty-eight security bulletins instead of one, and hoping that someone doesn't get a zero-day in a less used library that doesn't has much security attention paid to it

System administrators, developers of pretty much any language, and even chip designers have to deal with the issues related to code that wasn't written in-house. We live in a modular world.

But make no mistake -- you're writing a framework.

React and the Common JS module system are enough of a framework especially when compared to jQuery.

I'm getting the feeling that most people on this forum don't really know nor care how these tools work and are mainly interested in making snarky jabs.

Your criticism isn't digging deep enough in to these tools to even make much sense.

Re: You Don't Need JQuery

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

Note the Jquery ticket for this issue can be tracked link below. In most cases Jquery will try to use to native implementations this is the ticket in this case they've never found it to be "miles away more performant".

http://bugs.jquery.com/ticket/5087

Re: You Don't Need JQuery

#155

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 embedd…

It's better to just use one of the jquery versions hosted on the google developer cdn: https://developers.google.com/speed/libraries/devguide If you link to a popular jquery version, I bet the odds of the user already having the library cached is approaching 95%+ so your dependency is essentially free as no requests will be made in that case.

The odds approach 1.7%.

http://www.i-technology.net/2013/11/the-myth-of-cdn.html

more data: http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...

Re: You Don't Need JQuery

#156
post #26

Earlier quoted context omitted.

.classlist() [1] is coming [2]. It'll allow you to do: document.getElementById('foo').classList.remove("bold"); Sure, it's still more verbose. But a lot of what jQuery does is slowly being obsoleted by better native javascript apis. [1] https://developer.mozilla.org/en-US/docs/Web/API/Element.cla... [2] http://caniuse.com/#feat=classlist

So when those new native api functions arrive, jQuery will start using them and gain some performance boost (using native vs. custom js code) while at the same time remaining backwards compatible (by doing feature detection). No one wants to write their own feature detection code so this whole page about using native apis is instead of jQuery is ridiculous. If the point of that website was to educate people on the ap…

Or you could use the class list polyfill.

Re: You Don't Need JQuery

#157
post #23

Earlier quoted context omitted.

This may seem anecdotal, but I can tell you from writing a lot of non-jQueryified code that with modern browsers, applying classes to dozens of elements dynamically can be an anti-pattern. 99% of the time, when doing something which previously would have required that, I can use a single class on a parent element.

Not if you're in an environment (like mobile) where you want to reduce repaint.

In which case you don't want to be using jQuery at all and should instead be using a virtual DOM implementation like virtual-dom, famo.us, react or mithril.

https://github.com/Matt-Esch/virtual-dom

Re: You Don't Need JQuery

#159
I guess if you are super optimizing your website then getting rid of all the useless stuff is fine, but at least I don't notice big enough performance increase to get rid of jQuery even if it's just for the $('selector').

Re: You Don't Need JQuery

#160
Lately everything I build with jQuery I will eventually regret it. The first most annoying problem is that events triggered in jQuery cannot be seen by other modules correctly. Even not by another jQuery instance. There is also the usual size problem, when writing reusable code. For example whenever I want to reuse some 100 lines of code on another project I will have to add almost 100kb of jQuery to make it work. Working also on some bigger everlasting projects, like the wysihtml.com editor, has shown that when you need to patch some browser misbehaviours, native javascript is the only way to go. Such patches need to be as close to their error source as possible.
Post reply on HN