News for hackers. Stuff that matters.
Re:jQuery 3.6.2 Released by CM30 on Wednesday December 14, 2022 @01:41PM (#33987928)
Sorry if this sounds naive, but... do people still use jQuery for new projects? I was genuinely surprised to see it was getting releases anymore, given how much of its functionality can be done with native JavaScript now.
Re:jQuery 3.6.2 Released by smallmouth on Wednesday December 14, 2022 @02:17PM (#33988593)
Apology accepted, and absolutely! Myself and two other developers just kicked off a very non-tivial, data-heavy application for a Dow 30 that will be used by a maximum of 12,000 users. Using jquery will help us avoid a lot of thinking and testing time with the whole "gee, how would I do that in vanilla, let me look that up" process.
Re:jQuery 3.6.2 Released by ericb on Wednesday December 14, 2022 @01:58PM (#33988239)
One thing that gets forgotten about jQuery is that there's a tremendous library of very evolved components in its ecosystem. Sure, "you don't need jQuery" is true, but when you go hunting for components you'd rather not write yourself, man is there still some gravity there.

You ask yourself, "do I feel like writing a calendar selector widget today?" Trade some vanity and JavaScript puritanism and the question becomes "what color should I style it?"

Re:jQuery 3.6.2 Released by kypro on Wednesday December 14, 2022 @02:04PM (#33988381)
I've not used it in a new project for a long time, but I often still work on projects with legacy jQuery code.

The main reason to still use it imo it is simply that a lot of devs are familiar with the API and they have really good docs.

While I prefer vanilla JS for JS-light projects, I'm also aware of some cross-browser weirdness and combability issues you might run into with a vanilla JS project. The nice thing JQuery is that you know it will work as expected on the all browsers it supports so you don't need to worry about cross-browser testing your code. It also makes certain things easier to do like basic JS animations.

The main reason care about the latest releases is that they patch security issues from time to time.

Re:jQuery 3.6.2 Released by collyw on Wednesday December 14, 2022 @03:40PM (#33990199)
That was the main reason that jQuery got popular if I remember correctly (though I have always been an 85% backend developer).
Re:jQuery 3.6.2 Released by lelandfe on Wednesday December 14, 2022 @04:54PM (#33991157)
https://webkit.org/blog/12288/working-together-on-interop-20...

The various browsers have gotten together and work awfully hard to fix outstanding quirks. You'll still encounter cross-browser oddities here and there, but it's generally more in the order of, "X browser hasn't added this method yet"

Re:jQuery 3.6.2 Released by The_Colonel on Wednesday December 14, 2022 @06:09PM (#33992147)
Yes, the cross browser weirdness is nothing like it used to be.

The other raison d'être is the API, which is simply much better than even the latest DOM API. It's actually pretty remarkable that jQuery API feels spot on even after 16 years.

Re:jQuery 3.6.2 Released by eyelidlessness on Wednesday December 14, 2022 @08:02PM (#33993478)
I was jQuery’s target audience at its heyday and at least for me, the big thing it brought to the table was $ and what’s now called a “fluent API” ($ methods return $ instances unless they’re getters for primitives; it’s pretty much still my preferred way to explain the general concept of monads to people familiar with the pattern). Browser compatibility was just delicious icing on the cake.
Re:jQuery 3.6.2 Released by jamesfinlayson on Wednesday December 14, 2022 @08:48PM (#33993959)
Yeah I thought that many of the last few releases were security fixes more than anything.
Re:jQuery 3.6.2 Released by amflare on Wednesday December 14, 2022 @01:55PM (#33988209)
Yes. Technically you could always use native JS in place of jQuery and have the same functionality. But jQuery's power came from abstracting away some of the messier and more complicated elements and giving developers a more intuitive set of tools. Some part of this are less necessary today than when jQuery v1 came out (like `querySelectorAll()` vs `$()`), but other parts are still enormously helpful (like `$.ajax()`). So like always, it's a trade off. But it's still one that comes up as worth it as often as not.
Re:jQuery 3.6.2 Released by gabereiser on Wednesday December 14, 2022 @02:00PM (#33988296)
`$.ajax()` has been replaced entirely by `fetch()` [0]. The only remaining use-case I can see for jquery is the animation capabilities but even that can be replaced with animejs [1].

[0] https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/U...

[1] https://animejs.com/

Re:jQuery 3.6.2 Released by amflare on Wednesday December 14, 2022 @02:08PM (#33988446)
That's only mostly true. If you are working with anything that needs to support older browsers (which, for example, is unfortunately still a requirement in many medical, government, and financial sectors), then you can't use `fetch()`.
Re:jQuery 3.6.2 Released by duskwuff on Wednesday December 14, 2022 @02:26PM (#33988761)
You can polyfill fetch() if that's a concern:

https://github.com/github/fetch

Re:jQuery 3.6.2 Released by no_way on Wednesday December 14, 2022 @02:27PM (#33988787)
You can use fetch polyfill which woyld be better choice since its easier to remove polyfill than refactor your whole site once you don't need to support those old browsers anymore.
Re:jQuery 3.6.2 Released by amflare on Wednesday December 14, 2022 @03:36PM (#33990123)
Sure. I could also pull in axios or just bite the bullet and use the XMLHttpRequest API. The point isn't that jQuery is the only way to solve the problem, but rather that it still has a value proposition.
Re:jQuery 3.6.2 Released by LudwigNagasena on Wednesday December 14, 2022 @05:01PM (#33991234)
Being a “polyfill” with idiosyncratic API doesn’t sound like a good value proposition.
Re:jQuery 3.6.2 Released by LudwigNagasena on Wednesday December 14, 2022 @02:52PM (#33989229)
Babel?
Re:jQuery 3.6.2 Released by Beltalowda on Wednesday December 14, 2022 @05:40PM (#33991748)
I tried using fetch(). I naïvely passed an object as the POST form parameter and it sent the string "[object Object]" to the server as POST data.

Apparently you need to use some special object type. Why doesn't the universal key/value type work for passing a key/values? Who knows – maybe there's a good reason, maybe not. I do know that sending [object Object] is literally never what anyone could possibly want and that almost any other design choice would be less idiotic.

So I just use xmlHttpRequest or jQuery.ajax(). xmlHttpRequest is kind of awkward, but it's straight-forward and you don't get nonsense like this.

I also don't care much for promises, and fetch is pretty promise-heavy.

Re:jQuery 3.6.2 Released by gabereiser on Wednesday December 14, 2022 @05:59PM (#33992009)
You tried using fetch() without looking at the documentation on how it's supposed to be used? It's pretty clear [0]. You are supposed to JSON stringify your JSON payload so it can be attached to the body (as a string). The reason being that the browser isn't responsible for determining what goes into the request, only that you can make one. JSON isn't the only option. It could be YAML. It could be base64. It could be null.

[0] https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/U...

Re:jQuery 3.6.2 Released by Beltalowda on Wednesday December 14, 2022 @06:19PM (#33992276)
It's not clear that it will do something completely idiotic if you mess up a parameter. The documentation didn't mention it, so I figured I'd try and see what happens.

This is the worst of dynamic languages: if you mess something up and you get an error: okay, fair. If you mess something up and you ignore it or do something insane: that's just stupid.

"Read the documentation from cover to cover to something as simple as sending a HTTP request" isn't really much of solution.

> The reason being that the browser isn't responsible for determining what goes into the request, only that you can make one. JSON isn't the only option. It could be YAML. It could be base64. It could be null.

The standard data type for POST is form data, so it could just default to that for objects.

Or it could throw an error.

Sending [object Object] is not reasonable behaviour in any shape or form. I guess it just calls the JS "to string" logic ("logic"), but spreading that to new APIs is just not a good design, especially when it's "hidden".

Re:jQuery 3.6.2 Released by tehbeard on Wednesday December 14, 2022 @06:07PM (#33992109)
> Why doesn't the universal key/value type work for passing a key/values?

Because there isn't one?

By "itself" (i.e. <form> tags without JS), the browser can POST using two different encoding formats: - Url encoding (similar to what you'd see in the URI, but as the body of the request) - multipart/form-data (a derivative of MIME, needed for file uploads)

What's it supposed to do if you passed an object containing a CryptoKey instance, a Blob and a ReadadbleStream??

We also have a ton more ways of encoding and sending data in a POST (which is just the HTTP method, it doesn't convey anything bar that there's probably a body and related headers attached we want the server to do something with).

JSON, XML, CSV, YAML to name but a few key/value formats.

Hell, maybe it's an S3 style endpoint and you just push the raw bytes to save.

fetch is... less "magic" by default. This makes it flexible, but means you have to put just a tiny bit of effort into it.

Or... just use Axios, I ain't your manager; I get by easily enough with a helper js that gets treeshaked out so that I can just call `postJSON(url, body, opts=null)`

Re:jQuery 3.6.2 Released by Beltalowda on Wednesday December 14, 2022 @06:56PM (#33992768)
You can default to "application/x-www-form-urlencoded" and use "multipart/form-data" if requested, which is essentially how HTML forms work. There's lots of reasonable behaviours to choose from and you can discus what the best possible approach is, including throwing an exception, but sending "[object Object]" is not one of the reasonable behaviours.

> Or... just use Axios, I ain't your manager; I get by easily enough with a helper js that gets treeshaked out so that I can just call `postJSON(url, body, opts=null)`

The fact that everyone "just" has to use a wrapper for a basic system API is exactly the problem, especially when this was supposed to be the new shiny thing that would replace the old cruft. Why do I have to add 4 dependencies + 44 "dev dependencies" just to make a HTTP request?

Plus, for my personal projects I want to avoid the "npm ecosystem", and I especially want to avoid any JS build system.

Re:jQuery 3.6.2 Released by eyelidlessness on Wednesday December 14, 2022 @08:07PM (#33993535)
> Why doesn't the universal key/value type work for passing a key/values?

Because form data (and the FormData object which is what you’re expected to use) is often not a map (in the sense of key -> value) but rather a set of entries (as in, still a key-value container, but the same key might be present multiple times). They definitely could have supported a POJO but I personally like this bit of type strictness (and it’s easily abstracted away if you prefer, in whatever way you prefer).

Re:jQuery 3.6.2 Released by runarberg on Wednesday December 14, 2022 @08:23PM (#33993707)
CSS animations and the Web Animation API are also quite nice to use and quite powerful.

https://developer.mozilla.org/en-US/docs/Web/API/Web_Animati...

Re:jQuery 3.6.2 Released by ssl232 on Wednesday December 14, 2022 @02:12PM (#33988507)
Is jQuery able to use native browser functions internally if they're available? If so then there's probably not much of a penalty over using pure JavaScript, but a large benefit from the mature component ecosystem.
Re:jQuery 3.6.2 Released by udp on Wednesday December 14, 2022 @01:59PM (#33988280)
I’m not sure $.ajax() is a good example now that fetch is widely supported.
Re:jQuery 3.6.2 Released by jrochkind1 on Wednesday December 14, 2022 @02:13PM (#33988522)
i don't intentionally write code using JQuery anymore, and find it not very inconvenient to avoid for the most part, even when writing "jquery style" JS -- which I do. Browser API's in recent browsers are good enough.

But I'm still using some dependencies that need jquery.

I honestly expect I'll never be able to get rid of it.

Re:jQuery 3.6.2 Released by PrivateButts on Wednesday December 14, 2022 @02:06PM (#33988425)
jQuery is like, comfort food for me? Used to use jQuery for everything and now the world's moved on. I wouldn't want to do a large project today in jQuery, but I kinda miss the simpler projects that I used to do all the time with a smaller toolbox.
Re:jQuery 3.6.2 Released by bcrosby95 on Wednesday December 14, 2022 @02:21PM (#33988677)
The vanilla JavaScrip for lots of this stuff is pretty verbose.

It always surprises me how many people think jquery is unnecessary now. Developers obviously value ergonomics, and jquery is vastly more ergonomic than vanilla JavaScript. It's like saying Kotlin is useless because you can do all that shit in Java.

Re:jQuery 3.6.2 Released by pier25 on Wednesday December 14, 2022 @02:27PM (#33988775)
jQuery is more popular than React by pretty much any metric you can find
Re:jQuery 3.6.2 Released by collyw on Wednesday December 14, 2022 @03:43PM (#33990242)
for starting new projects?
Re:jQuery 3.6.2 Released by kbrannigan on Wednesday December 14, 2022 @04:15PM (#33990697)
Beginers and aspiring sofware developers tends to use the most popular technology, evangelized by the biggest companies.

Since they don't know any better, they equate MOST POPULAR with BEST.

Sometimes all you need is a wheelbarrow, you don't need a tractor.

Re:jQuery 3.6.2 Released by collyw on Thursday December 15, 2022 @08:24AM (#33999135)
BEST is highly subjective. Most popular has a number of advantages- more developers, likely cheaper developers, bigger community but for most cases I am in agreement with you
Re:jQuery 3.6.2 Released by pier25 on Wednesday December 14, 2022 @11:14PM (#33995116)
Yeah. There are probably more new projects started with Wordpress themes that use jQuery than React projects.

And it's not only WP. Plenty of big companies use it too. Amazon (the store) used it until a couple of months ago IIRC.

If you don't need a super sophisticated frontend, jQuery is still one of the best tools around.

People argue vanilla JS can do everything jQuery does, which is true for jQuery and any JS framework really, but they're really missing the point. With jQuery you can do express complex logic in a single line that would take many more lines in vanilla JS.

Re:jQuery 3.6.2 Released by thejammahimself on Wednesday December 14, 2022 @02:30PM (#33988833)
Yeah a good few years ago, before I had learnt about frameworks like React, I used JQuery for one of my projects. Once I learned about React, I decided to rewrite this project using that instead, and afterwards I felt that the React version was very obviously the superior version. I just feel like we now have better options, and I still really like React's way of handling state in a moreso functional way.
Re:jQuery 3.6.2 Released by tsian2 on Wednesday December 14, 2022 @02:56PM (#33989317)
I find it much quicker to write and neater to read than vanilla JS. I optimise afterwards and might consider swapping it out but it's usually low down the list of performance issues. Although it can be a bigger issue if you don't know how select things and store those selections efficiently with it.
Re:jQuery 3.6.2 Released by jabart on Wednesday December 14, 2022 @02:59PM (#33989382)
Bootstrap 4 uses jquery, bootstrap 5 was released (not beta) May 5, 2021. So, anything started with Bootstrap 4 would use it.
Re:jQuery 3.6.2 Released by yokoprime on Wednesday December 14, 2022 @03:20PM (#33989829)
I only encounter it when maintaining old codebases. Never for anything new
Re:jQuery 3.6.2 Released by ww520 on Wednesday December 14, 2022 @03:21PM (#33989845)
Yes. I do still use it.
Re:jQuery 3.6.2 Released by Alupis on Wednesday December 14, 2022 @04:09PM (#33990600)
The API jQuery gives you is still so much nicer than regular javascript, even with modern ECMAScript 7+...

While we're at it - Bootstrap (and similar css frameworks) are still much nicer to use than native CSS, even with modern CSS3 and flexbox...

It's almost like the designers for these native-API's look at what the community uses, and then decide to do something similar, but different just because.

Re:jQuery 3.6.2 Released by eyelidlessness on Wednesday December 14, 2022 @07:56PM (#33993420)
> It's almost like the designers for these native-API's look at what the community uses, and then decide to do something similar, but different just because.

This is an understandable interpretation, but I think the real explanation is more nuanced (and more favorable). Web APIs do tend to be inspired by existing use cases like you say, and that’s a good thing. But from there they tend to be low level—in the sense that they’re designed for library authors, at least as much as they’re designed for end users—either as an explicit goal or as an implied general principle.

Taking inspiration from real usage is unambiguously great. Lower level APIs might feel more painful for end users (and can lead to dependency-itis which is a constant target of scorn here and all over). But the benefit is that these less friendly APIs are also well designed to be used in a wider variety of ways, without much influence on their own higher level interfaces.

More concretely, the DOM as designed allows jQuery and React to coexist and thrive for their own target audiences, in a way that would probably be much less likely if the DOM had been designed more like either one of them. This is similarly true for APIs like Intl (which I’ve used directly, and it’s fine… but it’s definitely better as a library target than for every day usage).

Re:jQuery 3.6.2 Released by Alupis on Wednesday December 14, 2022 @08:14PM (#33993608)
Of course there are technical reasons things are the way they are - but why does javascript have like 6 different ways to select an element? Why does everything have to start with verbose "document."? Why are the new functions so long in name and cumbersome to use?

In jQuery, you can select almost anything with just the constructor. It's simple... and clearly better.

> in the sense that they’re designed for library authors

Libraries shouldn't be necessary to write basic DOM manipulation code. Modern ECMAScript has been promised to do away with all the "hack" libraries like jQuery... and articles like "You might not need jQuery" sprang up in popularity based on new ECMAScript features.

But, modern ECMAScript is objectively harder to use, more clunky and verbose. Even the naming of functions is absurd... "querySelector()" instead of just "select()" or "get()"...

The problem with the javascript community is nobody actually knows javascript. No, people know whatever framework/lib they work with, which is not the same thing. It's that way because javascript... sucks to use.

Re:jQuery 3.6.2 Released by eyelidlessness on Wednesday December 14, 2022 @10:11PM (#33994661)
> why does javascript have like 6 different ways to select an element?

Because all but one of them existed already when settled on the one that everyone almost universally prefers, but the others can’t be removed. You can just use the one you like and totally ignore the others.

> Why does everything have to start with verbose "document."?

Because it has to be namespaced to something, and the global document object is by far the best namespace available. You can destructure it once and even assign it to a global if you don’t like that reasoning.

> Why are the new functions so long in name and cumbersome to use?

Partly because people don’t like how things are so they do the global assignment thing and make sure no one can have nice things; partly because long names are self documenting which is often the best documentation they can guarantee at design time; partly because they expect people will never call these APIs directly.

> In jQuery, you can select almost anything with just the constructor. It's simple... and clearly better.

Clearly to you? I can think of a bunch of ways I’d rather access the current state of a document, and they can vary a lot depending on my task.

> Libraries shouldn't be necessary to write basic DOM manipulation code.

That’s a really odd position to take given you’re advocating the choices made by one!

> Modern ECMAScript has been promised to do away with all the "hack" libraries like jQuery... and articles like "You might not need jQuery" sprang up in popularity based on new ECMAScript features.

Modern ECMAScript didn’t make any of these claims, and didn’t set out to do any of the things jQuery does. ECMAScript has added some language features like let/const, modules, Symbol, classes, async/await. HTML added querySelector and a bunch of other DOM conveniences, as well as fetch. Browser vendors and other organizations have added other APIs for things people want to build applications on.

> The problem with the javascript community is nobody actually knows javascript. No, people know whatever framework/lib they work with, which is not the same thing. It's that way because javascript... sucks to use.

No, it’s that way because everyone wants JavaScript to be the thing they already shimmed it to be. You might be surprised by what it actually is. There are many problems with it of course, but it’s incredibly capable of being nicer to use than you seem to think.

As far as knowing JS, I’d highly recommend just spending some casual time reading MDN. Almost every time I do (which is fairly often) I discover something elegant that I either need immediately or could imagine being helpful soon.

If nothing else, it’s always a good insight into how the tools that do 95% of what I want get their job done.

Re:jQuery 3.6.2 Released by progmetaldev on Wednesday December 14, 2022 @04:21PM (#33990772)
I am still using jQuery because I have so many plugins such as calendars, photo galleries, video galleries, and file explorer type trees that are all progressively enhanced, it would be a ton of work to rebuild everything. I think jQuery is still does a great job for progressive enhancement of CMS/informational type websites.
Re:jQuery 3.6.2 Released by bigger_cheese on Wednesday December 14, 2022 @06:49PM (#33992682)
I used jQuery earlier this year.

I am not a web developer I learnt HTML in the 90's (When Frames and Tables were the way to write web pages). I have not kept up to date with current State of the art in web development. I know enough about JavaScript to read source code and kind of understand what it is doing but don't know anything about best practices or the 'proper' way to write it.

I needed to throw together a simple webform to submit a date as one of the inputs. I was having problems getting it to work consistently across different browsers.

One of the issues I was having was I needed the date to be in the Australian date format (DD/MM/YYYY) but one browser (I can't remember which Edge maybe??) kept insisting on using US style dates MM/DD/YYYY it caused me a lot of frustration maybe I just didn't know the correct phrase to search google for but I could not work out how to make the browsers built in calendar picker force the date to be in a specific format.

So I just used the JQuery calendar picker took me two seconds and problem solved.

Re:jQuery 3.6.2 Released by tambourine_man on Wednesday December 14, 2022 @07:54PM (#33993393)
It always could be done in JavaScript, jQuery is written on it after all.

It’s just that it’s a lot better and easier. The fact that we haven’t standardized on jQuery’s API is one of the greatest missed opportunities in the field.

Re:jQuery 3.6.2 Released by deterministic on Wednesday December 14, 2022 @07:57PM (#33993426)
Yep. It is the first package I install on a new project. Followed by React.