6 ms·
Second to that: jQuery is awesome. Or more specifically: the idea that websites can be built with vanilla HTML, CSS, and _optional_ JS. jQuery embraces progres
by tipiirai 3y ago
Second to that: jQuery is awesome.
Or more specifically: the idea that websites can be built with vanilla HTML, CSS, and _optional_ JS. jQuery embraces progressive enhancement and separation of concerns pattern, which is quite the opposite of how websites are built these days. Web development starts with 10+ React import statements for components, CSS, images, and whatnot. JavaScript is a must, not optional.
- p-e-w 3y agoOne website that almost always gets mentioned when people talk about jQuery today is "You might not need jQuery" (https://youmightnotneedjquery.com/ https://youmightnotneedjquery.com/). That site is the best ad for jQuery I've ever seen. For almost every task it describes, the jQuery code is shorter, cleaner, and more intuitive than the vanilla "modern" JS one. And that's after almost 20 years, and I don't know how many billions of dollars invested into advancing JavaScript.
- tipiirai 3y agoIt's the jQuery API design. I often find myself creating functions like this one: export function $(query, root=document) { ... } jQuery acted as a role model for standard web committees. The argument for querySelector / querySelectorAll calls is literally mimicked from John Resig's groundbreaking API design.
- cxr 3y ago[flagged]
- tipiirai 3y agoAbsolutely yes. jQuery selector engine was developed before the official Selector API, which ended up being almost exactly the same. Except for a few exceptions which John wasn't too sure about when they asked for feedback: https://johnresig.com/blog/thoughts-on-queryselectorall/ https://johnresig.com/blog/thoughts-on-queryselectorall/
- cxr 3y agoI don't know what you think that link shows (I don't know what John thought it showed, either—it's a classic "talking to one's own head, instead of who you're trying to communicate with" situation, and David Baron's confusion on the mailing list at the time is understandable). To reiterate: > The argument for querySelector / querySelectorAll calls is literally mimicked from John Resig's grounbreaking API design No, it wasn't. "The argument for querySelector / querySelectorAll calls" is literally ... CSS's selector language, which predates jQuery by about a decade. And the idea to make a library function to match against selectors was conceived of and implemented by Simon Willison years before jQuery was released, spawning lots of copycats. jQuery was literally named jQuery because writing a library to do this was the hotness at the time and one such library Resig had used was called cssQuery. (jQuery does do a lot more than just match CSS selectors, but what that involves is not something jQuery has in common with querySelector—it's nowhere near "almost exactly the same". The result of a jQuery call has a weird, jQuery-specific shape. (It's not an element node). If Simon's getElementsBySelector did what jQuery did, Resig wouldn't have written jQuery.) This is a matter of public record, and to state or suggest otherwise is worse than just being wrong. It misleads and confuses people. <https://twitter.com/simonw/status/1536129600232665088 https://twitter.com/simonw/status/1536129600232665088> <https://www.slideshare.net/jeresig/history-of-jquery https://www.slideshare.net/jeresig/history-of-jquery>
- jve 3y agoSo you couldn't get away with lazy and ignorant two word answer and it forced you to write quality one :) One would argue whether we'd have querySelector if jQuery wasn't as popular. We may have an inspiration chain here... but thanks for pointing out to prior art.
- deleted 3y ago[deleted]
- cxr 3y ago[flagged]
- Finbarr 3y agoThis is incredible and such a great ad for jQuery. It's almost as if the creator(s) built that site ironically. So many examples are way clearer and easier in jQuery, like this one: JQUERY: $(el).toggle(); IE8+: function toggle(el) { if (el.style.display == 'none') { el.style.display = ''; } else { el.style.display = 'none'; } } Gotta love that "modern" triple attribute repetition. From: https://youmightnotneedjquery.com/#toggle https://youmightnotneedjquery.com/#toggle
- 1123581321 3y agoToggle was a bit of a pitfall because the developer had to keep track of all the possible states prior to that line. It's easy to drop in as a function when needed in simple scripting (expanding faq sections, etc.)
- extra88 3y agoA more modern solution would be to use classList.toggle() or toggleAttribute(hidden).
- mschuster91 3y ago> Gotta love that "modern" triple attribute repetition. You can golf it down a bit: el.style.display=el.style.display == 'none' ? '' : 'none';
- anakaine 3y agoEven though I can appreciate the elegance of your solution, I'd prefer the former for clarity.
- OJFord 3y agoSurely el.style.display = el.style.display ? 'none' : '' (after toggling we've already obliterated any possible third value for it anyway, doesn't seem significant)
- Finbarr 3y agoOf course. Because that's infinitely better than: $(el).toggle();
- LamaOfRuin 3y ago>For almost every task it describes, the jQuery code is shorter, cleaner, and more intuitive than the vanilla "modern" JS one. Just like leftpad.
- ipaddr 3y agoInstead of needing to import leftpad you have the missing standard js lib
- krapp 3y agoIt isn't missing. Javascript was created to serve a specific purpose, which didn't include left-padding text in a terminal. Most language I'm aware of wouldn't have that in their standard lib. If you want Javascript to act as a drop-in replacement for C++ or Java or some other general programming language (which Javascript was never intended to be) don't act as if needing to write libraries to cover that missing functionality is a problem with the language. You're using the wrong tool for the wrong job.
- selcuka 3y ago> Most language I'm aware of wouldn't have that in their standard lib. Python has str.ljust [1] (and str.rjust [2]): > Return the string left justified in a string of length width. Padding is done using the specified fillchar (default is an ASCII space). The original string is returned if width is less than or equal to len(s). [1] https://docs.python.org/3/library/stdtypes.html#str.ljust https://docs.python.org/3/library/stdtypes.html#str.ljust [2] https://docs.python.org/3/library/stdtypes.html#str.rjust https://docs.python.org/3/library/stdtypes.html#str.rjust
- Macha 3y agoC has it in their standard library, basically forever. See the list of specifiers to printf. C! If it fits into the C standard library, it's not bloating the Javascript standard library.
- 3y ago
- jampekka 3y agoMuch of the billions are used to make JavaScript worse. E.g. ESM is a byzantine mess compared to CJS, and the ceremony and bondage of TypeScript is dramatically increasing busywork.
- admaiora 3y agoYesterday I was checking HN from 10years±2weeks ago and guess what the top posts were... "Why you need jQuery" and "You might not need jQuery". I'm too young to know about those days but I guess not much has changed in relation to people's attitude towards jQuery.
- krapp 3y agoWhat's changed is the billion dollar tech industry invested in convincing people that JQuery is a dead and obsolete technology. For some reason, JQuery is the exception to the general rule of seeing a mature, battle-tested library as a sign of quality.
- Macha 3y agoThe problem jQuery was solving was to provide a usable abstraction over an inconsistent platform for core functionality like event handling and DOM manipulation. The point of the last decade and a half of standards work was to eliminate that problem, and it has at least moved it from "core web functionality" to more complicated areas like bluetooth, 3d rendering and audio, which jQuery's goals do not include handling. Is it urgent to remove jQuery from projects? Not really. And it's good the jQuery team maintain the project for that reason. Certainly some projects have gotten performance gains out of removing it, but part of the work they've done in 3.x and now 4.x is arguably jQuery removing stuff internally and replacing them with the now reliable browser APIs. But on the other hand, is there a great argument for including jQuery in new projects? This is also a "not really".
- collyw 3y agoIt was initially sold as a way to fix browser incompatibilities, but I still use it because there are really nice plugins like select2. I really don't see the point in SPA apps for the most part. Fair enough if you have a heavily interactive frontend, but I can build an app in Django with a bit of JQuery and end up with around half the code compared to adding in React.
- gunapologist99 3y ago
- marcosdumay 3y agoThat site message is "don't import all of jquery just to use the $ global and one or two specific functions". It's a very fine message and the site contents spread it quite well. But if you actually want to use jquery instead of just some function you got from a reference, by all means, use it, it's a very nice library.
- nextaccountic 3y agoAbout optional JS: you can have that with server-side rendering plus a modern framework (like next.js or leptos). That's certainly not as simple as vanilla html and js, but totally doable.
- tipiirai 3y agoYou sure can, but it then comes to the separation of concerns. CSS-in-JS (coupling of concerns) is the preferred option.
- teaearlgraycold 3y agoHaving CSS in a separate file feels like defining the predicates for your if statements in a separate file. With tailwind we're getting pretty close to a great solution here.
- shadowbanned4 3y ago[dead]
- kkarpkkarp 3y ago> you can have that with server-side rendering plus yes, we use PHP for this which is much simpler to grasp than JS-SSR
- geek_at 3y agoplus you don't need to restart any services or rebuild servers. Just git pull and you have the new code on the live server without even a second of downtime
- flemhans 3y agowatch -n 1 git pull
- wouldbecouldbe 3y ago
- PrimeMcFly 3y ago> JavaScript is a must, not optional. I build plenty of CSS only sites without any JS just fine. I avoid using it as much as I can and generally only need it for forms or galleries, occasionally some ajax stuff. But it's seldom required.
- manuelmoreale 3y agoJust want to say I appreciate you for doing that.
- PrimeMcFly 3y agoThanks :) It just seems like good practice. I want my sites to be as fast, minimal, compatible and as usable as possible, while still looking and feeling modern.
- manuelmoreale 3y agoI hear you. My site is 1 http request and no js so I’m definitely with you on this.
- midasuni 3y agoYesterday I wrote a custom page which dumped out a table for some investigation. I threw jquery and a tablesorter plug-in. Without JS you get the table, but with you can easily sort and filter. Took about 2 minutes to add the optional filter. The backend is bash of course.
- sireat 3y agoFor tables my favorite jQuery plug-in is: https://datatables.net/ https://datatables.net/ Have a page with some tables? A few lines of jQuery and you have search sorting etc. It can be customized but defaults are fine. This is how abstractions and progressive enhancement should be done.
- midasuni 3y agoI’m not even sure what I used, it’s the same 5 lines I’ve used for years. Boom bang and on to the next problem. For every unicorn saas webapp $300k a year developers are writing there’s a thousand small pages. If you’re building a house you aren’t going to use a Swiss Army knife, but if you’re camping out for a couple of days you aren’t going to take a van full of power tools.
- anakaine 3y agoA couple.of well selected power tools are certainly helpful, however. A battery blower to start the fire, a small electric chainsaw for any wood cutting depending on the area and what you take in, and a portable fan if you're in a hot climate. Sometimes a couple of selected power tools are very helpful.
- ryanisnan 3y agoWeird analogy. I’ve camped my whole life, never once brought a power tool.
- GrumpyNl 3y agoBig plus is, it also gives yo the option to export the tables to pdf and other file formats.