r/webdev • • Feb 13 '19

Bootstrap 5 will remove jQuery as a dependency

https://github.com/twbs/bootstrap/pull/23586
1.5k Upvotes

398 comments sorted by

View all comments

Show parent comments

212

u/kilakewe Feb 13 '19 edited Feb 13 '19

Think of jQuery as a millennium Falcon Lego box kit. Out of the box, it makes something pretty cool, but if your trying to make a little Lego dog, you've got a whole lot of pieces that never get used, but you have to carry them around anyway.

This is how vanilla JavaScript fans feel about jquery

Edit: typos

59

u/bmey Feb 13 '19

To piggy back on this, here is a great resource for how to do the same things jQuery does with vanilla JS: http://youmightnotneedjquery.com

46

u/shellwe Feb 13 '19

You don’t need it... but I see that first example on JSON and the jquery is 1 line of code where the vanilla JS is 10 lines. It’s hard to be motivated to do the 10 line version when I can do the 1. It would be nice to see ES2015+ examples since we would use Babel to scale back to 9 anyway.

53

u/lookingforusername Feb 13 '19

TBF the "equivalent" examples are a bit dated... For example, a modern version of

$.getJSON('/my/url', function(data) { });

would be

fetch('/my/url').then(res => res.json()).then(data => { });

or async style:

res = await fetch('/my/url');

data = await res.json();

// do stuff with data

19

u/SupaSlide laravel + vue Feb 13 '19

Of course the equivalent examples are dated, they're intended to work in old versions of IE so that they support the same versions as jQuery. You can't use fetch instead of jQuery if you need to support IE9.

9

u/WhyLisaWhy Feb 13 '19

Just use something like babel to compile your ES6 code. Jquery really isn't necessary anymore and honestly its better to just get more fluent with ES6 for your career anyways. None of the technical architects at my company are interested in new hires knowing Jquery anymore.

5

u/dons90 Feb 14 '19

None of the technical architects at my company are interested in new hires knowing Jquery anymore.

Pretty much this. If you ever plan to work in modern front-end development, you should ditch JQuery, preferably yesterday.

→ More replies (1)

7

u/shellwe Feb 13 '19

Yeah, there isn’t really a reason that site should have IE9 compatible solutions. Everyone should write with the latest JS code and then have Babel scale it down to whatever version you need.

16

u/gonzofish Feb 13 '19

Yes, the developer ergonomics is better but you end up shipping ALL of jquery to do it

15

u/andrerav full-stack Feb 13 '19

Just once usually, because caching. I assume CDN is still a thing too? How large is the base jquery library these days anyway?

7

u/gonzofish Feb 13 '19

The 3 alpha was minified at 83 KB, unminified is 250 KB. But the point is that you don’t need a library to do a lot of stuff anymore (thanks a lot to jQuery pushing us forward). You’re swapping 10 lines for 1 but also the other 83 KB of stuff you may not need.

10

u/KnightKreider Feb 13 '19

Their point is you're not grabbing anything new since the dependency is used so prevelently and almost certainly cached if you use a CDN.

I do agree that most modern browsers support the majority of what jquery is used for though.

7

u/electricity_is_life Feb 13 '19

I mean yeah but you don't have to look at the 83 KB of code. I'm really happy with all the stuff that's easy in vanilla JS now, but I don't really understand why people so badly want to get rid of jQuery. I don't use it for every project, but when it will be useful I don't see much reason to worry about the extra 30kb of (gzipped) data. Most of my images are bigger than that.

→ More replies (1)

1

u/bmey Feb 14 '19

See my top-level comment about the css tricks article. It has some modern examples.

4

u/DerKnerd Feb 13 '19

This is kind of outdated since a few things changed. Fetch and CSS animations for example and I think classList is missing too.

1

u/bmey Feb 14 '19

here is one from CSS tricks that calls out some modern examples - https://css-tricks.com/now-ever-might-not-need-jquery/

22

u/nyxin The 🍰 is a lie. Feb 13 '19

And out of your Millennium Falcon LEGO kit, we all know you only REALLY use the selector engine and click controls for the most part when your building your ship.

So we decided we’d rather build a faster millennium falcon from scratch without all the extra pieces we don’t need.

(ps. I don’t hate jquery. It had its time and place and made a lot of things better. We’ve moved on and these tools are no longer needed for their intended purpose. jQuery needs to be remembered fondly and forgotten.)

6

u/[deleted] Feb 13 '19

A faster Millennium Falcon, you say? How many parsecs did it take in the Kessel Run?

→ More replies (2)

2

u/the_other_dave Feb 13 '19

Also, there was a time when carrying around the entire Millennium Falcon kit was the easiest way to build a small dog out of Legos. Back when jQuery was more popular the vanilla JavaScript tools were not what they are today.

2

u/z500 Feb 13 '19

Vanilla C fans just use inline assembly

1

u/test6554 Feb 13 '19

As long as it's not a crutch, use it all you want. I don't see how react/vue/angular is any more efficient for making a lego dog.

→ More replies (27)