by DrSiemer · 2y ago · 0 comments
Yes, the vanilla selectors are more verbose, but any half decent code editor will make them just as fast to type. I don't mean to be penantic, but I don't really understand why so many people still use jQuery at all.
And what are we saving by eschewing it and going vanilla? One little 30kb-gzipped javascript file - smaller than most jpegs. I agree for super simple tasks it might be best to skip it.
The DOM API is a sloppy and hastily-designed pile of crap from the OOP era that we're unfortunately stuck with for legacy reasons. jQuery shows what it could have been.
Ends up eliminating 50-60% of the code, and the time for writing and reading it.
As for jquery I haven’t needed it much since stimulusjs but loved it whenever I used it.
wat
DOM APIs have been, and still are, 90s-era OOP style with zero attempt at being functional, declarative, or composable.
Even the newly developed API are usually stuck in the same mindset (see everything developed for web components)
You can modify the code to set the display property as inline-block, but now you need a different show function for every possible display value you want to restore. Or you need to build a layer of state to remember what the original value was and hey you've rewritten the jquery version.
And this is all ignoring that the jquery versions just look so much simpler to remember and are cleaner to read.
```css .hide { display: none important!; } ```
```js function hide(el) { el.classList.add('hide'); } ```
You'll likely be adding 6-700KB of React and its ilk anyway (I see it in every project now).
With jQuery it feels like a lot of functionality is hidden away, which can lead to unexpected situations that are harder to debug.
In my experience writing vanilla code takes less time, not more, because I have a better grip on what is happening.
The great things about these plugins is that you can strip them down to what you need and patch them yourself (remember lib or vendor directory). NPM and build tools make this a chore.
It could be argued that avoiding unnecessary work is my main job function. It's a lot more efficient to just get something that already does what I need, without requiring patches. In my experience leaving the jQuery ecosystem made this a lot easier.
Because it has a beautifully designed API. I don't directly use jQuery usually anymore. But I use the API in a basic DOM wrapper I've written. https://gist.github.com/pseudosavant/b86eedd9960ade958d49447...
I'm convinced this site is actually satire and it designed to promote jQuery. In nearly every example, the native version is far more verbose.
These days I find vanilla far easier to read and it is a lot more clear to me what is actually happening in the code.
Depending on jQuery limits your ability to work with code that does not use it. Ie a lot of the more professional libraries.
For me dropping jQuery feels like a step up. Why don't you just try it, see what happens. It's just a day of being a little bit annoyed and then you should be fine.
jQuery might be a crutch, sure, but I'm not sure crutches are a bad thing. There's no reason to make something harder than it has to be. I just like how some things take far fewer key stroke and are less verbose, but still readable.
Readability is subjective. There are people that think Perl is fine and I think it ranks as one of the least readable languages to ever reach popular status. Meanwhile, I think Python is the most readable language to have ever been created, and somehow some people struggle with it, and tbh it kind of blows my mind.