235 points · by mkurz · 7y ago · 162 comments
Just to abuse metaphors, I believe that jQuery is a "bicycle for the mind" in the true Steve Jobs sense. If you don't love it, please knock yourself out or try an edgier SPA. Spend all of your free time learning how Hooks just made everything you were excited about obsolete.
The pool is warm and the weather is lovely, friends.
Not all websites are SPAs or need fancy interactivity, some are rendered server side and jQuery does simple manipulations,
Also there are many good UI components for jQuery and I seen the big frameworks wrapping 6this components.
I don't believe that contemporary webdev's main problem is how we construct a SPA. I think it's the assumption that everything needs to be a SPA.
I suppose there's the alternative of "ship HTML and forget about Javascript for the most part", but very, very few people are following that nowadays, and besides which, JQuery supports a "Javascript not required" progressive enhancement model far far more than most other front-end frameworks.
I prefer fetch, document.querySelectorAll, and animate.css for 90% of what you would need with jQuery.
You know how there's ~3 kinds of Excel users? You have your formatted rows and columns types, people like me that can use SUM(), call APIs and know what pivot tables are... and then there are those ninjas that can implement ray-traced dungeon renderers in a cell. https://www.youtube.com/watch?v=iCeOEQVUWZ0
I'm not exactly claiming Carmack-level jQuery proficiency, but comments like yours make me wonder (optimistically) whether you've forgotten all of the amazingly useful things that jQuery can do. Ajax, selectors and CSS transitions are the Nickelback of creative possibility.
As a final note, I am excited that things which once required jQuery are now being solved by the browser and the evolving EcmaScript standard. Ideally, jQuery continues to get smaller and smaller. However, it's intellectually dishonest to claim that all of the non-jQuery techniques are as ergonomic to implement as jQuery idioms. Proof:
http://youmightnotneedjquery.com/
I do really like fetch and async/await in general, and working in React has taught me lots of cool tricks to bring back to my real projects. I think everyone should try to build something real with React, just to understand how lucky they are to have the option not to use it.
I spent all of five minutes glancing through the example list and noticed their `replaceWith` doesn't provide the functionality that jQuery offers -- it doesn't take into account event handlers bound to DOM elements. Also, their `extend` does a shallow merge, not a deep merge. Furthermore, the YMNNJ examples are often far more verbose and less expressive than the jQuery examples.
I don't particularly understand the rush to rip jQuery out of everything. It seems like a lot of people are doing it just because it's the trending thing to do. There are some things that jQuery does very well -- even in today's world where modern web dev is dominated by SPA components.
I'm the maintainer of https://github.com/elliotnb/observable-slim and https://github.com/elliotnb/nimbly -- the latter of which is an SPA component framework whose core requires jQuery. It uses jQuery to update DOM nodes with `replaceWith`, merge deeply nested objects with `extend`, among other things. Nimbly components are not required to use jQuery -- only the framework core uses it. Aside from the eliminating the extra 69KB footprint from adding jQuery slim min, I don't see any reason to rush to rip jQuery out of the Nimbly core. On the contrary, using jQuery helped us get the framework built faster and helped us keep the code expressive and easy-to-follow.
It's been several years since I last used jQuery, but what are those other useful things that are hard using Vanilla.js? (Legitimate question, not being sarcastic here)
The examples in the site already look quite outdated. We now have `fetch()`, `.attachEvent` is all but dead, plus all the ES6 features like arrow functions, destructuring, spread... and reactive UI means you'll rarely, if ever, need to call DOM tree modifying methods yourself.
The best part, "Reactive UI" being a paradigm, you have many other options besides React+JSX, for example https://github.com/jorgebucaran/hyperapp. At a fraction of the size of jQuery, which one is the 'monster'?
I don't use React/Vue/Flavor-of-the-month UI library for my day job; however I don't use jQuery either.
I am not trying to shit on what can be accomplished with it; however, I debug a lot of code that adds it in where ES6/vanilla javascript does the same thing. I guess I prefer verbose javascript over using jQuery... not trying to knock on it, but it might be worth looking at other tools for the long term.
Edit: To be clear, I am not advocating to rip out jQuery fron existing apps. In a lot of cases, jQuery and jQuery plugins are helpful, but most of the code that I am paid to debug ends up being rewritten in vanilla js because I feel comfortable using that. I stopped using jQuery a while back because I opted to use a UI library a while back and worked hard to avoid jQuery ever since even though I don't use UI libraries at my current job.
Use whatever tool floats your boat and doesn't piss off the rest of your team. It's possible to ship spaghetti code in any flavor you want. I happen to (currently) work on things where the level of complexity of the UI is simple enough to use vanilla JS and not need a UI framework.
And the jQuery Ajax methods are super-handy. POST with the fetch API is long-winded; while the jQuery promise-handling sucks, it was enough to make me use $.post() in the current project.
If you're worried about backwards compatibility, then jQuery is the right tool; however, if less than 2% of your users are using an unsupported version of Internet Explorer, I would spend more time flashing a message instructing these users to upgrade.
I agree that jQuery is ok for simple things, however I'd probably prefer something more light weight, like Bliss.js instead. jQuery's 30kb bundle size does make pages load slightly slightly slower on mobile phones, in comparison to Bliss (about 3kb last time I checked).
In my experience React front-ends are more driven by separate data retrieved and stored at the server, while jQuery front-ends are mostly server-side rendered and jQuery is used for some degree of dynamic flexibility.
At my work, we've been building SPAs with jQuery long before Angular or React even existed. More recently, we've built our own JavaScript SPA framework whose components can be written with vanilla JS or jQuery. Most of us prefer to use jQuery for our components because the syntax is often more expressive and concise than vanilla JS.
We recently open sourced the framework: http://github.com/elliotnb/nimbly
After gzipping those with 7-zip (on windows now, too lazy to do anything other) the sizes are 4 035 bytes for bliss and 29 495 bytes for jquery.
The same in table:
minified min+gzip
jquery 86 927 29 495
bliss 11 823 4 035This was, I don't remember, something like 30 or 100 ms, for jQuery — on my core i7 laptop (according to Chrome Dev Tools). Might mean ... maybe 200 ms? half a second? on an a few years mobile phone.
I think you are comparing apples and oranges. Jquery is absolutely awesome for automating parts of your pages, and/or adding substantial interactivity.
If you are building an actual SPA, as in application (think gmail and the like) you wouldn't want to use jquery.
More often we expect something to happen, and the cases where the results might be empty are obvious enough that adding a “fail silently” flag in those cases wouldn’t be a hardship.
Biggest category of bugs I had to help people with, aside from performance regressions from abusing reflow.
As hardships go, I’ve had worse with other frameworks. But if I could g9 back in time or if I were trying to make a workalike...
The set-operatic approach of jquery is one I absolutely love about it, though it does lead to unforeseen behaviours in edge cases (sometimes performance concerns running code on nothing or on way more than expected) it's leads to extremely convenient and fluent code, much more so than the explicit iterations of the normal DOM.
> More often we expect something to happen, and the cases where the results might be empty are obvious enough that adding a “fail silently” flag in those cases wouldn’t be a hardship.
Extending jquery to assert a lower bound (and even an upper bound as well) wouldn't be a hardship either.
So when I saw jQuery for the first time, I’d already been primed for this concept. I’m a little surprised it’s been used so infrequently.
You spend 10 times more time writing so much more code having to make the UI 'react' to the changes that you wish to see.
With React/Vue/Angular it's just a case of adding a conditional.
With jQuery you've gotta do something like
jQuery('.this').hide();
jQuery('.that').show();
jQuery('.thisotherthing').show();
Gets really confusing, hard to test and hard to maintain.
Then when you want to do things with fancy selects and dynamic option choices and all that good stuff it just gets even more unruly.
With modern JS frameworks you declare a state and your UI reflects your state. Rather than with jQuery having to manage both the state and the UI all at the same time.
I'm forced to use nothing but jQuery at work so I'm quite competent with it so it's not from lack of experience. It provides nothing but pain and misery.
> With jQuery you've gotta do something like jQuery('.this').hide();
Sure, at some level, you're going to have define a relationship between your data and some display element (`jQuery('.this')` above), mechanisms for managing presence & visibility among other characteristics (`.hide()` in this case), and wiring that to state.
React is a set of shortcuts and conventions for doing this. It's a decent solution and saves on thinking about how to organize code for this task, and more important saves on bad thinking about how to organize an application (a savings that multiplies the larger the team working on it and range of experience within).
But it's certainly possible to write plain old JS (augmented with jQuery for convenience, if you like) where you define that relationship between your data and display element and accompanying mechanisms once and all the data->UI flow is encapsulated in functions where you don't worry about DOM specifics.
There's some marginal increase in verbosity, and you have to be the person who enforces the conventions (which is usually where this falls down), but OTOH, you get a little more control over how the semantics of your application are encoded. YMMV.
$('.this, .that, .thisotherthing').toggle();
Or if you're looking to throw in a conditional, toggle takes a boolean argument:
$('.this').toggle( foo === undefined );
Really it depends so much more on whether or not you're designing a single page app or have some interactive elements on an isolated webpage. Use the correct tool for the correct job.
But it's not just that. You've got to account for stuff like updating classes on elements, updating text (e.g you might have a dropdown and when you change that dropdown it updates a summary bar), managing configuration of various components on a page (like options within a select dropdown, available dates in a date picker) etc. etc.
All becomes a lot easier using something like React/Vue and they even throw in dev tools to make it easier furthermore.
Also, maybe it is from lack of experience. Because you can add classes to your elements and depending on them you can hide/show all of them with just
$('.toggle-element').toggle();Trying to scope it all gets a bit unruly too. Your example would target every element on the page. If you have nested components it’s a nightmare.
Hey, if whatever works for you is awesome, please carry on. But if you're behind schedule, the SPA is too slow, the users say it's buggy, most of your devs couldn't manipulate the DOM directly if they were forced to, and the lead just spent until midnight getting the build working right, then you might want to start examining some of your development and architecture choices.
I love tools and abstraction frameworks -- right until the time they start taking over more time, effort, and learning than just pounding a solution out in something like JQuery would.
I'm glad the update is out. Looking forward to playing around with it some ... the next time I need something as full-featured as it is. With greenfield development, we start with zero stuff and carefully justify each addition after that.
I believe there is a use case of every technology. There are use cases where React/Vue makes sense, similarly, there are still use cases where jQuery can be useful.
jQuery is not an alternative to React or Vue. It's an alternative to vanilla JS.
When you're writing something that doesn't obviously need everything a reactive app framework like React offers the question you need to be asking isn't "Do I need React or do I only need jQuery?", it's simply "Do I need jQuery?". These days, unless you need to support very old browsers, most of the time the jQuery code isn't that much simpler than writing plain old JS.
React and Vue are geared towards solving a specific part of that problem.
Without a very good reason, most developers shouldn't be trying to solve the problems Vue and React solve in jQuery/JS. Of course, some will want to and nothing's stopping them, but I wouldn't recommend it for _normal_ projects.
Advocating ignorance seems, I don't know... ignorant?
The only sound argument for JQuery when not using react/vue/Ang. is the plugin ecosystem.
Otherwise current browser techniques (document.querySelector/All, fetch, map/reduce/filter/some etc) with polyfills does a better job.
Vue is definitely lighter than jQuery, and the reactive model with components tends to work better. Also you don't need any building process (Babel, Webpack, etc) unlike React. You can perfectly write your templates in the DOM.
That said, for some use cases I still prefer using vanilla or a Cash (a jQuery replacement).
As libraries go I think jQuery's one of the nicer ones I've used. I don't use it now, but it's pretty good software in my books and I'm glad it was there when I needed it.
Sorry for repeating your point in so many words, but the hate towards jQuery really gets me down.
Top 1m 77.15%
Top 100k 87.37%
Top 10k 88.83%
https://trends.builtwith.com/javascript/jQuerySearch “jQuery” in there, first result will be the copyright comment plus the version.
jQuery got its niche today. Still the best for simple one-off landingpages.
I also think there's a lot of people still using jQuery simply because they're scared of SPAs, the learning curve involved and how they basically change the role of a front end dev to more of a fullstack dev.
I once considered myself a front end dev but these days I'm using SPAs, running NodeJS, pulling & managing data from REST APIs, sending / retrieving stuff from a database, managing NoSQL database, using serverless functions, working with websockets and GraphQL etc..
Am I still considered a front end developer? Because I know front end developers who still carve a living out of HTML / CSS / jQuery alone. They'd be toast when it comes to present day job interviews for example for front end positions. It just seems like we need to split 'front end developer' in to about 3 or 4 levels to better represent people's skillset / what's expected of them.
FTA
Specifically, jQuery 3.4.0 is deprecating :first, :last, :eq, :even, :odd, :lt, :gt, and :nth
With nowhere near the convenience and clarity of selectors e.g. $("foo bar:first baz qux") or event delegation.
Lots of first, last, and even, odd usage.
Obviously, the abstractions were what made jQuery what it is, and what made it so powerful, but I wish that vanilla JS were to take a leaf out of jQuery's book and adopt some of its syntax ideas.
You just need to know when to pick the right tool for the job.
I tried vuejs recently for a little interactive page on my website and found it revolutionary compared to jquery.
There are still lots of people who can't sadly.
That said while yes you can do everything jQuery does in vanilla JS (jQuery is written in vanilla JS after all) you often end up with more code than using jquery which means more to read through, more to understand.
So saying it is useless is a bit harsh, it may be useless for you but it's not for many and if you look at what the jquery folks are doing with deprecations you can see they are refactoring jquery to use the vanilla js stuff that was added in large part because of jquery so it'll likely definite itself out of existence at some point anyway.
However, jQuery apps built 10 years ago still work flawlessly and updating plugins generally doesn't break the app. Newer solutions like React change so much that if you have an app that you built and left there without updating it chances are after 1-2 years it won't even compile without replacing components that are no longer available.
Are you all building websites like that? Returning blank page from server and then filling all content on client side?
It's a great library and I am thankful for the people who have made and contribute to it. I've used it during my web development career years ago before client side rendering was a thing.
I believe if they were to meet their goal of modernizing it, jQuery will be going on much longer regardless of other framework out there.
Reactive data with vdom is nice for some use cases, but sometimes the best solution is to manipulate the dom directly.
Does anyone know of some library that can mix the two approaches?
I am not going to name what obnoxious framework it is about, but I am waiting for another year or two before they unceremoniously abandon that stuff and start hyping the next Messiah framework.