News for hackers. Stuff that matters.
Re:The Future of Htmx by recursivedoubts on Monday January 06, 2025 @02:04PM (#42614112)
That may or may not be the case (see https://youmightnotneedjquery.com/) but the fact remains that jQuery is used on 75% of all public websites.
Re:The Future of Htmx by ofrzeta on Monday January 06, 2025 @03:01PM (#42614964)
That might be related to Wordpress including jQuery.
Re:The Future of Htmx by The_Colonel on Monday January 06, 2025 @03:20PM (#42615218)
That website is (inadverently) one of the most effective marketing campaigns for jQuery. Some of the vanilla JS examples are atrocious.

What it doesn't show is that vanilla JS is not chainable (jQuery is).

Re:The Future of Htmx by Bengalilol on Monday January 06, 2025 @04:30PM (#42616100)
What do you mean ?

  let result = "   hello jQuery   "
  .trim()
  .replace("jQuery", "javascript")
  .toUpperCase();
  console.log(result);
map, filter, ...

  let numbers = [1, 2, 3, 4, 5];
  let result = numbers
  .filter(num => num % 2 === 0)
  .map(num => num * 2)
  .reduce((sum, num) => sum + num, 0);
  console.log(result); // 12
Simple string

  let myStr = "This is a wonderful day.";
  let reversed = myStr
  .split("")
  .reverse()
  .join("");
  console.log(reversed); // ".yad lufrednow a si sihT"
  
DOM elements

  document.querySelector('#element')
  .classList.add('active')
  .classList.remove('hidden');
Using a class

  class Chainable {
    constructor(value) {
      this.value = value;
    }

    add(num) {
      this.value += num;
      return this; // make it chainable
    }

    multiply(num) {
      this.value *= num;
      return this;
    }

    getValue() {
      return this.value;
    }
  }
  let result = new Chainable(5)
  .add(3)
  .multiply(2)
  .getValue();
  console.log(result); // 16
Re:The Future of Htmx by deniz-a on Monday January 06, 2025 @07:50PM (#42617970)
Re:The Future of Htmx by Bengalilol on Tuesday January 07, 2025 @03:49AM (#42620597)
Oops. You are right, I beg your pardon. Here's a working example.

HTML

  <span class="a b c"></span>
JS

  function getClassList(el) {
    let ele = document.querySelector(el);
    let list = ele.classList;

    return {
      add: function (c) {
        list.add(c);
        return this;
      },
      toggle: function (c) {
        list.toggle(c);
        return this;
      },
      remove: function (c) {
        list.remove(c);
        return this;
      },
    }
  }
  getClassList('span').remove('b').add('e').toggle('a');
  console.log(document.querySelector('span').classList);
Re:The Future of Htmx by hu3 on Tuesday January 07, 2025 @05:35AM (#42621172)
Congrats you're reinventing jQuery. With a worse and more limited API.

Plus jQuery is one of the most battle tested libraries in the world.

That "ops" you made with classlist, you're bound to repeat these mistakes ad infinitum. And they can bite in subtle ways only your users might experience.

People rarely report broken websites unless they really need to.

Re:The Future of Htmx by Bengalilol on Wednesday January 08, 2025 @03:22AM (#42632189)
I am truly interested in your arguments on why using chainable DOM Elements leads to less buggy websites.
Re:The Future of Htmx by hu3 on Wednesday January 08, 2025 @08:20AM (#42633900)
You're the only one making that claim.

Plus using a homemade alpha version of jQuery written by one dev leads to more bugs, not less.

Re:The Future of Htmx by Bengalilol on Wednesday January 08, 2025 @08:37AM (#42634059)
> That "ops" you made with classlist, you're bound to repeat these mistakes ad infinitum. And they can bite in subtle ways only your users might experience. People rarely report broken websites unless they really need to.

I think those two sentences are out of bounds, but I somehow get you. Yet I don't get the 'broken website' remark (took it condescending, or is it from experience?).

Mainly, I was replying to the affirmation that javascript is not chainable which is (imho) an indication of how one could get disconnected to the underlying lang by simply relying on libs such as jQuery (and I am thinking the same about htmx). Thanks for your reply!

Re:The Future of Htmx by The_Colonel on Tuesday January 07, 2025 @06:59AM (#42621534)
Thanks again for a nice demonstration of having to reinvent the wheel to produce a poor-man's buggy reimplementation of jQuery.
Re:The Future of Htmx by gjsman-1000 on Monday January 06, 2025 @02:06PM (#42614133)
Notice how the “modern” is almost always more verbose than JQuery.

JQuery might as well be a shorthand JS library.

Re:The Future of Htmx by matharmin on Monday January 06, 2025 @02:19PM (#42614332)
I view JQuery as similar to C in some ways: It's been around forever, it's mature, and it works. It gives a good experience to get something up and running quickly: it's lightweight and simple.

But if you're working on bigger projects: It is possible, but have have to be very principled in how you use it, otherwise you're going to end up with either a massive spaghetti codebase and lots of edge cases in your app that breaks.

Alternatives like React and Rust may add more complexity upfront, but the improved structure and safety it gives has big benefits in all but the smallest projects.

Re:The Future of Htmx by peebeebee on Monday January 06, 2025 @02:28PM (#42614462)
Not so sure about that. You can easily write horrible code in React: Too complex, inefficient, and/or resource-intensive. If you don’t know the tools and have good theoretical programming knowledge, all code will be spaghetti code in the long run.
Re:The Future of Htmx by klabb3 on Monday January 06, 2025 @04:16PM (#42615950)
I'm no fan of React, but these aren’t equivalent. If you follow the rules, react (or any of its alternatives) will manage stateful changes like adding and removing components and event listeners. JQuery is more similar to doing manual memory management in C. It’s extremely easy to get it wrong and introduce leaks and other non-local errors.
Re:The Future of Htmx by bdougherty on Monday January 06, 2025 @04:40PM (#42616219)
React is also extremely easy to get it wrong.
Re:The Future of Htmx by klabb3 on Tuesday January 07, 2025 @05:35PM (#42628507)
Can you give an example? I mean I know you can shoot yourself in the foot with any UI framework, but jQuery has no way of managing state, everything just leaks by default. Unless they’ve added something.
Re:The Future of Htmx by The_Colonel on Monday January 06, 2025 @03:17PM (#42615179)
I don't disagree, but this is not relevant for the vanilla JS vs. jQuery discussion, since vanilla JS has exactly the same problems you mention as jQuery.
Re:The Future of Htmx by recursivedoubts on Monday January 06, 2025 @02:09PM (#42614172)
it's a good API! and consistent!
Re:The Future of Htmx by Bengalilol on Monday January 06, 2025 @04:58PM (#42616431)
Have a look at jQuery 'load' :

<https://github.com/jquery/jquery/blob/main/src/ajax/load.js>

Then at the vanilla JS 'load' :

  const response = await fetch('/path/to/template.html');
  const body = await response.text();
  document.querySelector('#some.selector').innerHTML = body;
IDK, all in all it is a proxy functions lib.
Re:The Future of Htmx by paxys on Monday January 06, 2025 @06:18PM (#42617253)
Those stats are pretty meaningless. How many of those websites haven't been updated in the last 7 years? Not that there's anything wrong with that, but the decisions they made a decade ago aren't necessarily still the best ones today.
Re:The Future of Htmx by EasyMark on Monday January 06, 2025 @06:42PM (#42617452)
How is that meaningless? It seems that web users of the site at least find it acceptable and aren't complaining enough to the site builders that they feel the need to change the website. AKA the website is standing the test of time. That's kind of a huge bonus when it comes to saving money and time to the website maintainers.
Re:The Future of Htmx by paxys on Monday January 06, 2025 @09:54PM (#42618655)
The point is that if you were to start building a new website from scratch today, the best tools for you aren't necessarily the most widely used ones. You have the option to start with a clean slate without any baggage. There are no upgrade costs. There are no customers who will get inconvenienced. There is no inertia. You are in a very different position than someone who has a website with millions of lines of jQuery already in use.
Re:The Future of Htmx by yellowapple on Friday January 10, 2025 @12:48AM (#42652944)
Even with a clean slate, there's immense value in choosing something that you already know to be a tried-and-true approach - i.e. in choosing "boring" technology¹ instead of trying to be at the cutting edge.

Now if exploring the cutting edge is a goal of yours in and of itself, then by all means blow some of those innovation tokens on the new Reactangular.ts hotness. For a lot of projects, though, the goal is to get something out the door as painlessly as possible; jQuery and plain JS have (for better or worse) been the tried-and-true "boring" approaches, and HTMX (from what I can tell) seeks to be the similarly "boring" choice.

Obviously right now HTMX ain't the boring choice (because it's still pretty new), but a decade from now it could be. Having used it in a couple pet projects recently, it already does feel pretty boring (especially since it goes hand-in-hand with other boring strategies like "just use SQL" and "just use CGI scripts" / "just use classic MVC frameworks").

----

¹ https://mcfunley.com/choose-boring-technology