DEV Community

Discussion on: Do you still work with jQuery?

Collapse
 
tylerlwsmith profile image
Tyler Smith

I still use jQuery with WordPress, and I don't expect that I'll stop any time soon. Most of the time a Wordpress plugin will need to load jQuery anyway, and it's really nice for sprinkling JavaScript onto a static page. I write less code than I would with Vanilla JS, and it has animations & ajax built in. Sure, I could piece animations & ajax together another way, but I don't see the reason when jQuery has both.

I'm not a luddite: I use React when I build full-blown web applications. I've also used ES6 features to build apps with Vanilla JS before. But unless bundle size is a major constraint, I still feel perfectly happy reaching for jQuery in 2021.

I wrote about this more extensively in my article with the clickbait-y title, "Hating jQuery doesn't make you cool." Link below 😊

Collapse
 
janmpeterka profile image
Jan Peterka

Do you prefer ajax to fetch for some particular reason? as BE dev I'm bit lost in these things, so I will be glad for more insigth into this :)

Collapse
 
tylerlwsmith profile image
Tyler Smith

I sure do. Fetch is too low level for my taste: I don't like having to parse the response for the HTTP code to decide how to handle errors. I almost always prefer jQuery's ajax() method or the Axios library for ajax instead of raw fetch requests. They handle a bunch of things automatically that I'd have to code myself with fetch.

Collapse
 
matthewbdaly profile image
Matthew Daly • Edited

Have you looked at Alpine.js at all? I quite like that as a jQuery replacement because:

  • It's tiny - it and Axios together are still only a fraction the size of jQuery
  • It provides a more declarative API, largely copied from Vue

These days I don't really like including jQuery by default on new projects because a lot of it simply isn't needed, but at the same time doing a lot of that stuff in vanilla JS can be a chore. Alpine's so far proven to be a good solution for what I used to fall back to using jQuery for.

Collapse
 
imthedeveloper profile image
ImTheDeveloper

In the same way I'm doing with Vue.js, drop in the script tag and swap out the JQuery. I'll check out Alpine, Vue I just seemed to "get it" quite quick.

Thread Thread
 
tylerlwsmith profile image
Tyler Smith

Alpine has almost everything I like about Vue without the build the steps. It's one of the best front-end tools to come out in the past few years.

Thread Thread
 
imthedeveloper profile image
ImTheDeveloper • Edited

Yep with the cdn script there is no build for Vue either so fully with you on such a low impact way to improve

vuejs.org/v2/guide/installation.ht...

Collapse
 
philw_ profile image
Phil Wolstenholme

+1 for Alpine, I love it when working with server rendered pages.

Collapse
 
tylerlwsmith profile image
Tyler Smith

Alpine is absolutely amazing. It's become my favorite tool for adding interactivity on server-rendered apps that I build with frameworks like Laravel. And Alpine recently added an equivalent of jQuery's slideToggle(), which is the feature I needed most often from jQuery.

I'm not terribly concerned about the extra kilobytes I get from using jQuery. jQuery doesn't block the DOM from rendering, and it doesn't require activation bootstrapping the way that a framework would: it just needs to download and parse. It's very different than React where you can't render anything until the library is downloaded, parsed, and your app code executed. Even server-rendered React has issues with links not working until the app is fully hydrated.

Avoiding extra kilobytes is nice, but it's easy to go down a rabbit hole where we focus on reducing the kilobytes of JavaScript because it's easier to measure than other higher-impact UX like avoiding page jank, creating useful error states, avoiding responsive issues, etc. Alpine feels nicer to use in a lot of cases though!