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

138

u/bmey Feb 13 '19 edited Feb 14 '19

If you are interested in how to remove jQuery from your project, here is a great resource for how to do the same things jQuery does with vanilla JS: http://youmightnotneedjquery.com

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

66

u/benp18p18 Feb 13 '19

Also a good site http://vanilla-js.com

13

u/Mike312 Feb 13 '19

Every time it gets posted I always have to go back and re-read it. It's so sardonic about what it is.

12

u/mumrik1 Feb 13 '19

I like how they add the script tags in the jquery examples just to give the first impression it's just as much code lol

6

u/Edores Feb 14 '19

Yeah holy shit, obviously jQuery isn't targeted at people who want to use a single feature a single time.

I'm all for cutting out bulk but this is just masturbatory.

5

u/Ajedi32 Web platform enthusiast, full-stack developer Feb 14 '19

Those examples really need to be updated to use fetch and CSS transitions. Then it'd be comparable even without the tags.

9

u/ILoveDCEU_SoSueMe Feb 13 '19

I don't get this. Is it a framework or is it just a parody site that just wants to say use Javascript as it is?

I'm a beginner.

25

u/VeryAngryBeaver Feb 13 '19

It's a paradoy site making fun of those so attached to frameworks they haven't been keeping up with how regular javascript has improved and that they don't need most of the libraries they think they do.

6

u/examinedliving Feb 14 '19

It’s really amazing what regular JS can do - but!!!!!! It’s still a pain in the ass dealing with browser support. It’s getting less relevant hopefully, but its nice not thinking about that with JQuery.

JQuery can lead to some bad code on large sites, but it isn’t such a bad thing as it’s made out to be. Perhaps it’s ubiquity pisses some people off.

3

u/benp18p18 Feb 13 '19

It shows how you can use just plain JavaScript instead of a framework which is really helpful.

I had the same thought when I first came across it.

0

u/[deleted] Feb 13 '19

[deleted]

→ More replies (1)

1

u/participationNTroll Feb 14 '19

I got duped the first time too when I saw the zipped version wasnt 0 bytes

→ More replies (1)

5

u/jeffreyhamby Feb 13 '19

Came here to add that one :)

2

u/[deleted] Feb 14 '19

This framework is slick. The minified version downloads super fast.

3

u/kwhali Feb 13 '19

Does it work for web scraping via node at all?

cheerio(which I ended up using) seems to use jquery style api.

5

u/mawburn Feb 13 '19

Cheerio is jQuery. Here is the description on their github:

Fast, flexible, and lean implementation of core jQuery designed specifically for the server.

Cheerio is great for web scraping and it's usually my go to if I need to scrape statically generated pages, because the DOM API doesn't exist on Node.js.

2

u/kwhali Feb 13 '19

because the DOM API doesn't exist on Node.js.

Right. So I should stick with cheerio then? I figure you could possible run vanilla JS like in a browser to do it without cheerio if the code ran on something like PhantomJS? Then again, that'd probably need some other layer to communicate with Node if you want to do node specific stuff like save the scraped output to a file on disk... sooo cheerio?

5

u/mawburn Feb 13 '19

There's nothing wrong with cheerio. The arguments here about jQuery have to do with the frontend, not really with jQuery itself.

I would advise against PhantomJS because it hasn't been supported for a while, but if you need to simulate a browser Google's Puppeteer or NightmareJS are decent options. These aren't really solving the same problem, though. If you're scraping static data and don't need to execute any kind of JS on the page, then stick with cheerio.

1

u/kwhali Feb 13 '19

So it's more about jquery is bad client side because of it's size? I don't really have use for the vanilla equivalents or jquery on frontend personally as I use react there these days.

But if the frontend argument is largely you probably don't need jquery when you think you might because plain js is good enough now, than not sure how that makes jquery any different in other contexts that it could be used?

Either way, my scraper is working fine as is with cheerio. Cheers for the suggestions, not sure what cheerio is using under the hood but I'm happy :)

1

u/Arve Feb 14 '19

So it's more about jquery is bad client side because of it's size?

Size and in many cases also speed.

5

u/Harbulary-Batteries Feb 13 '19

jQuery is a client-side technology. You don't need it / can't use it on node.js and shouldn't really worry about it. cheerio uses jQuery because they are actually parsing the HTML received by the server. There's nothing at all wrong with using cheerio's jQuery selectors to scrape HTML -- when people talk about using vanilla JS to phase out jQuery, they mean on their client-side code.

→ More replies (2)

2

u/lwilina Feb 13 '19

jQuery needs a DOM to operate on. When scraping you’re just getting the raw HTML markup from the server. If you wanted a DOM you would need to parse it first, like the browser would normally do.

According to this article you could do that with JsDom and then operate your jQuery on it. But, I believe, this is more or less what cheerio does internally as well.

1

u/[deleted] Feb 13 '19

[removed] — view removed comment

1

u/bmey Feb 14 '19

Css tricks has one (cleverly named as a sequel to the original article I linked) but it isn’t as exhaustive: https://css-tricks.com/now-ever-might-not-need-jquery/

Also, don’t miss the point - which is that jQuery just isn’t necessary anymore with modern browsers. It was great for its time. We should ideally use native APIs when possible.

→ More replies (10)