6

Do you still work with jQuery?

 3 years ago
source link: https://dev.to/ben/do-you-still-work-with-jquery-4o3g
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

For folks who still work with jQuery, for personal or professional projects, what is the overall context of this work? Do you expect this to be refactored at any point?

Discussion (28)

pic

CollapseExpand

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 😊

Comment button Reply

CollapseExpand

Author

Nov 17

Personally it's been a couple years since I've worked with jQuery. In general I'd say it's only a good thing if you can refactor your code to vanilla use of modern native dom query helpers, fetch calls, etc.

Comment button Reply

CollapseExpand

+1. It's been years since I last used jQuery, and I don't miss it at all. Besides if you really really really need jQuery's API, you can just use alternatives like cash, so actual jQuery is still not a good option.

Comment button Reply

CollapseExpand

I heard a few years ago that jquery was outdated and wasn't really in use anymore. I usually use plain DOM and created a little function to help me with document.querySelector()

const $ = tag => document.querySelector(tag);

Comment button Reply

CollapseExpand

Yes. No plans to refactor. It makes mine and my developer's lives a lot easier.

Our projects are LAMP stack and don't use modern JS frontends.

Comment button Reply

CollapseExpand

Author

Nov 17

I wrote this post years ago about jQuery at the time...

But have since come to think that it is effectively no longer needed (I think the fetch API put me over the top). Can you elaborate on what keeps you around the most?

Comment button Reply

CollapseExpand

Predominantly the readability. I find jQuery a lot easier to read than JS.

I see this site referenced a lot: youmightnotneedjquery.com/ But all it does for me is prove how much I prefer jQuery!

Take the getJson function for example:

jQuery

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

});
Enter fullscreen modeExit fullscreen mode

Javascript

var request = new XMLHttpRequest();
request.open('GET', '/my/url', true);

request.onload = function() {
  if (this.status >= 200 && this.status < 400) {
    // Success!
    var data = JSON.parse(this.response);
  } else {
    // We reached our target server, but it returned an error

  }
};

request.onerror = function() {
  // There was a connection error of some sort
};

request.send();
Enter fullscreen modeExit fullscreen mode

I know which I prefer...

jQuery also comes with the added benefit of slideToggle() functions, fadeIn/Out() functions, etc.

And I can just $('.classname') to target something, rather than document.getElementsByClassName(className)... it's just such an effort to write that much.

Time is money, and jQuery helps me do what I need to do quicker ! :)

I appreciate my team and I would need to transition to Vanilla JS if we start to use more frontend frameworks, and we are looking to bring in Vue to some of our projects in the future. But our LAMP systems (Wordpress/Drupal/CodeIgnighter) are still our bread-and-butter projects, and using jQuery in them just makes our lives easier.

I'd also argue modern frontend frameworks are still mostly in their adolescent stages, where they're still trying to stabilise themselves/their role in the future of the web... Vue has been around for 7 years, React 8 years, and Angular only 5 years; whereas jQuery has evolved over 15 years and understands its place in the world.

Thread

Thread

Just so you know, nowadays, if you want to load a JSON, you can just use fetch which is way easier than XMLHttpRequest and it doesn't require a library to use it. It uses promises so is arguably more readable than the callback approach of jQuery. The actual "versus" looks like this:

$.getJSON("/my/url", console.log);

// vs

fetch("/my/url")
    .then(response => response.json())
    .then(console.log);

// And if you use await...

const response = await fetch("/my/url");
const data = await response.json();
console.log(data);
Enter fullscreen modeExit fullscreen mode

You might think: "But hey! jQuery is shorter" ... and that's true, but for fetch we didn't need to load 30k of minified+gzipped jQuery code in order to start fetching our JSON. And that's not even talking about transferable knowledge (if you learn fetch, you can fetch in apps with and without jQuery, if you learn $.getJSON, you can only fetch if jQuery is present).

Cheers!

Thread

Thread

CollapseExpand

Not since about 2 years ago, but I got so used to their selector syntax, that I just use $ instead of document.querySelector in the chrome dev tools - yeah that is already implement in there by default 😎

Comment button Reply

CollapseExpand

I work in healthcare tech and a lot of my company's products make heavy use of jQuery. There's been some push to remake some things in React and to start using React for newer projects, but I'm skeptical that it'll actually happen any time soon.

Comment button Reply

CollapseExpand

I work with it when I have to, but given the choice will go with vanilla js or something more modern when needed. I sometimes have to work with older systems (magento 1, old junky wordpress sites, etc.) and removing a jquery dependency is out of scope.

Comment button Reply

CollapseExpand

There is tons of software out there still using it, we use jQuery DataTables and DataTables Editor since they are very polished and work great. We also have a lot of legacy code in production and sometimes a little jQuery can deliver the interactivity we need on the page without needing to use a modern frontend framework with build steps and bundling and all that.

Refactoring also takes time and there is a lot to do and a lot of things that need to be built before there is spare time to refactor things that are working just fine in production and are not overly complex to maintain. You also have to weigh the costs of bringing in complex SPA frameworks, build steps, cicd stuff, and tooling that a whole team will need to learn and that will be around for a while.

We have some web software that is in prod and that is 20 years old. Is there any framework like React, Vue, Angular that are in prod for 20 years with no updates needed?

Comment button Reply

CollapseExpand

Somehow I dodged that bullet. :D

In 2006 when jQuery was released, I was neck deep in PHP and I didn't build web apps with JavaScript until 2011. At that time I had the impression jQuery was legacy and nobody uses it anymore, so I didn't bother to look more into it.

I built my first JS project with ExtJS 4 in 2011.

Then I had a short project at university in 2014, where I used Ember.js, so I guess I used jQuery indirectly, haha.

In the next job I got in 2015, they were already using React, so I went with that, and later did some React-Native projects as a freelancer later.

But the first JavaScript book I read 2011 was "Pro JavaScript Techniques" by John Resig, so I guess, I can't deny that jQuery had some influence on my JS journey :D

Comment button Reply

CollapseExpand

I have a couple of big projects that use jQuery. We expect to keep it until the entire sites are rebuilt, because there's no point replacing it really.

When I edit javascript files that're already using jQuery, sometimes I use it and sometimes I write modern vanilla javascript, but these sites have no build process that would convert modern script into anything suitable for obsolete browsers - and some sites still have to support vintage tech.

Comment button Reply

CollapseExpand

I work with a few clients for whom sites were built during the Browser Wars days, when jQuery was everywhere like a battlefield hospital. Fifteen years later, these folks are still using jQuery, Backbone (precursor cousin to Angular) and perl. And they actively resist updating. They want the code maintained at this point, because it works and it's intimately tied to many aspects of their business.

Do they need jQuery? Absolutely not. Would the business benefit from an overhaul? Absolutely. Can they afford an overhaul? Likely, if done with a strategic plan, in stages. But they are terrified of having this spaghetti code castle collapse if someone makes a significant change.

So until i can convince them to either replace parts in stages or to run parallel servers so we can deploy and test under load... They're sticking with what works.

Comment button Reply

CollapseExpand

I'm using it when I absolutely have to.
Even when the project uses jQuery, I still write vanilla JavaScript.

Comment button Reply

CollapseExpand

Interesting fact; if you (only) use 50 KB+ jQuery for its Selectors, IE9 was the last browser to implement .querySelector .... in 2011

Comment button Reply

CollapseExpand

I skipped jQuery while I was playing the tuba. By the time I came back, Angular 2 was a baby, so I jumped back in with TypeScript.

Comment button Reply

CollapseExpandCollapseExpandCollapseExpand

Unfortunately, yes. But we are slowly rewriting it to vanilla.

Comment button Reply

CollapseExpand

I still use it when working with Shopify projects, usually because it's convenient to copy UI logic on codepen, a lot of amazing example up there still use jQuery.

Comment button Reply

CollapseExpand

Yes, occasionally. Legacy code can live for many years. Refactoring it would not be cost-effective. It's not like jQuery is evil.

Comment button Reply

CollapseExpand

Those who do freelance for admin panel apps using old tech like PHP and Bootstrap CSS probably still stick to jQuery. And maybe Wordpress developer still use it

Comment button Reply

CollapseExpand

Nooope leaved JQuery since Bootstrap bêta v5 is here. And now, full JS vanilla homemade. JQuery isn't anymore in my ❤️

Comment button Reply

CollapseExpand

Only when maintaining old projects that need "quick fix". But almost everything I do now is either ES or Vue

Comment button Reply

CollapseExpand

Absolutely and I love it. Not considering JS frameworks right now.

Comment button Reply


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK