by reificator · 9y ago · 0 comments
https://www.webreflection.co.uk/blog/2016/04/22/about-jquery
Lots of folks like to shit on jQuery these days, but it changed JS forever. We're still using it while focusing on other things, and you can easily swap it out for something else or use a ported version of our JS for React, Angular, etc.
In short, yes, and we'll get there in time <3.
I don't particularly aim to shit on it, but I've been on the vanilla train for awhile now. So when I see something I'd like to try out to solve a specific problem, having it pull in jQuery for a dependency is kind of frustrating.
Especially when (and I'm sure Bootstrap does more with it) the only reason it's pulled in is to replace document.querySelectorAll and fetch/xhr.
Very exciting! I have been slowly removing jQuery from many web apps over the last several years and its good too hear that Bootstrap wants to get there too :)
Now obviously removing jQuery would be a major revision and break the current API. But are there any particular pain points in removing jQuery as far as features go?
A cursory look at the source code (/js/src/*.js) shows that most jQuery usage is simple $(el).hasClass('foo') or $(el).on(evt, handler) so those ones are easily replaced by the native APIs.
Maybe the harder parts to replace are $.data or $.event?
If by some miracle you were able to find a website visitor that didn't already have jQuery in their cache, loading it from a CDN is pretty light.
The article answers your question:
>the most plausible answer is that jQuery is very good at plugins integration, and Bootstrap has few of them
Their solution? A 50-line JS snippet paired with a polyfill (the the user is less-likely to have cached than jQ). Er, ok, but I'm using a framework so I don't have to write this stuff.
Another example:
>OK, OK … I got it, you also want the chained $(element).on(type, handler) one
And then another snippet. Sure, I could rewrite more verbose, less-tested versions of all the things jQuery gets me OOTB, but why? To save downloading one file from a CDN once?
Sorry, that's my bad for forgetting my audience. My day to day job is to keep things running in IE8 in Quirks Mode. (With a really bad WYSIWYG editor to boot, inside of one of over 30 frames loaded on the page)
So in my eyes, IE10 is pretty modern. Not so to the average HN reader. My bad.
Still, IE10 is definitely close enough to standards that most of jQuery is wasted on it. Not all, and the parts that are helpful are indeed better tested than writing something yourself.
But I find once you start targeting IE10+, most of the time jQuery is a thing to hang pseudo globals off of, and a way to type `$` instead of `document.querySelectorAll`. And in that role, it's not worth the cycles it burns.
EDIT: In particular, the thing that gets me is when I go to look up a library and it is only available as a jQuery plugin. But looking inside the code the only uses of jQuery are for selectors, events, and http requests, all three of which are standardized and easy to use without jQuery.
Last I looked at jQuery was a few months ago, and all I saw was standard or compat.
EDIT: Just looked it up, it's still pretty big for my tastes, but I appreciate any reduction in size. Next time I need to bring in jQuery I'll see if I can get away with just slim.
It's in your cache because it's useful; at least your concede that it is likely to be in a user's cache, in which case the added page weight is 0.
Seeing as my argument was so terrible, I'd think you'd have an easier time forming a substantive reply, vs the struggle we see here.
I don't really understand the value added in your personal attacks.
Yes. These "plugins" are making your page heavy and wasteful and I hate browsing websites made by these "luddites" because they're slow and annoying and probably selling my information to advertisers.
>It's in your cache because it's useful; at least your concede that it is likely to be in a user's cache, in which case the added page weight is 0.
It's not like the browser caches the entire JavaScript JIT output. There is a performance impact and more importantly there's a cognative impact from having to use jQuery to interact with Bootstrap on top of whatever sane library (or lack thereof) you're using for everything else.
>Seeing as my argument was so terrible, I'd think you'd have an easier time forming a substantive reply, vs the struggle we see here.
What sort of substantiation do you think I'm missing?
>I don't really understand the value added in your personal attacks.
I didn't issue personal attacks, I attacked your argument. I have no commentary about you as a person leaving aside this one issue I disagree with you on.