Hacker News new | ask | show | jobs
by noble_pleb 2144 days ago
Is it worth switching from jquery with all the extra verbose code you must write for DOM manipulation?
1 comments

Yes, absolutely.

First of all if you use querySelector or querySelectorAll for everything your code will likely be smaller without jQuery, but it will be just as slow.

If you access the DOM with string parsing your application can be anywhere from 1200-10000x faster. It will be more verbose, but certainly not as much as most people fear. If you are good with scope and abstractions you will solve for most of the verbose DOM interaction with reuse and custom abstractions.

So really dumping jQuery means choosing between smaller code or substantially faster code and both are a win.

Opinions vary on that one, does a footprint reduction by 90kb really matters in the day and age where megabytes of bloatware like angular, react, vue, etc. goes unchecked?

If adding 90kb helps me write `$(document.ready()` instead of `window.addEventListener(DOMContentLoaded)`, I'd rather add that because making code more intuitive and readable is what software engineering is about.

I prefer to assign events handler's directly to node event properties instead of addEventListener. The only advantage to addEventListener is that you can plug in a bunch of marketing spyware nonsense without worry that its going to clobber your event assignments.
"If you access the DOM with string parsing" -- could you explain that for a noob?