Live data from Hacker News

Let's make the worst Htmx

zserge.com

71–80 of 85 posts

Re: Let's make the worst Htmx

#71
post #61

I really want to try htmx but it specifically prohibits my most common usecases: 1) I want to take a JSON response, create HTML from it, and replace the target element with the generated HTML. 2) Similar to the above, take a JSON response, perform some action, and do nothing to the source element. Is there a plugin to add this? I want to move away from jQuery, and having a small framework to wire up hooks would be us…

Why are you so wedded to JSON responses? HTMX is meant to be used to render html; my big HTMX app basically never(1) renders JSON, so much so that I have a standing instruction to coding agents that if they're rendering JSON they're probably doing something wrong. If you're attached to JSON because you're working with external API s you don't control, a good place to perform those kinds of actions is in your backend,…

Why are you so wedded to JSON responses?

I'd assume because of the conception that json = data. Html = presentation. But if you just use barebones html, this could work very well. Just add a wrapper in the api to return json as html to try it out a bit.

Re: Let's make the worst Htmx

#72
post #50

HTMX is amazing on paper, not in real life. It loses things like scroll position and text highlighting on re-render - it’s not high performance like React. This is for server sided or static web pages not building rich UI. There is no robust state management or DOM performance improvements you get with React with larger components. HTMX team should build a game with it. Load some 3D in WebGL/WebGPU, showcase high per…

> HTMX team should build a game with it. Load some 3D in WebGL/WebGPU, showcase high performance UI. Why? Why you'd pick htmx (or even reactjs?!?) to build a game?

Probably because the news of frontend's death has been overstated.

Re: Let's make the worst Htmx

#73
post #50

Earlier quoted context omitted.

> HTMX team should build a game with it. Load some 3D in WebGL/WebGPU, showcase high performance UI. Why? Why you'd pick htmx (or even reactjs?!?) to build a game?

Probably because the news of frontend's death has been overstated.

How does this answer the question? I cannot imagine an internal monologue going like this:

- Hm, maybe I should use react for this

- ok, why react?

- because the news of frontend's death has been overstated

???

Re: Let's make the worst Htmx

#74

Earlier quoted context omitted.

Probably because the news of frontend's death has been overstated.

How does this answer the question? I cannot imagine an internal monologue going like this: - Hm, maybe I should use react for this - ok, why react? - because the news of frontend's death has been overstated ???

- Why would you pick $backend technology?

- Because someone told me frontend was dead.

Re: Let's make the worst Htmx

#75
post #61

I really want to try htmx but it specifically prohibits my most common usecases: 1) I want to take a JSON response, create HTML from it, and replace the target element with the generated HTML. 2) Similar to the above, take a JSON response, perform some action, and do nothing to the source element. Is there a plugin to add this? I want to move away from jQuery, and having a small framework to wire up hooks would be us…

Why are you so wedded to JSON responses? HTMX is meant to be used to render html; my big HTMX app basically never(1) renders JSON, so much so that I have a standing instruction to coding agents that if they're rendering JSON they're probably doing something wrong. If you're attached to JSON because you're working with external API s you don't control, a good place to perform those kinds of actions is in your backend,…

I want to handle a JSON response because I usually return data for multiple page elements. These aren't external APIs, they're requests to the backend server.

A simple example is adding a note to a product or order. When you submit it, it gets inlined, and say a visual note counter is incremented. Usually I'll return multiple HTML fragments if it's convenient, but I'll return a data structure if needed.

Re: Let's make the worst Htmx

#76
post #28

Earlier quoted context omitted.

The problem with HTMX is not network traffic but needing to use hyperscript for anything advanced.

Also don't you entirely lose typing? My favourite thing about TSX is that it is typechecked. How do you do that with random strings of HTML?

I still write tsx and my components look very similar to react -- just no hooks. The difference is I render to html server side and send the rendered html. Look into it in hono

Re: Let's make the worst Htmx

#77
post #32

I highly recommend everyone to give htmx or datastar a try, especially if your main experience is react or nextjs. We recently rewrote a half-million LOC codebase from react to datastar, with a detour through htmx first, and the results are staggering . First page load is 20KB down from a 750KB js bundle. 1 network request vs 40+. Total load time 0.1 seconds down from 2 seconds of spinners. Page refresh is so fast, t…

If anyone is looking for a TypeScript framework that embraces hypermedia the same way that HTMX does (and is very easy to use with HTMX), check out Hyperspan: https://www.hyperspan.dev

Disclaimer: I built Hyperspan :)

Re: Let's make the worst Htmx

#78
post #61

Earlier quoted context omitted.

Why are you so wedded to JSON responses? HTMX is meant to be used to render html; my big HTMX app basically never(1) renders JSON, so much so that I have a standing instruction to coding agents that if they're rendering JSON they're probably doing something wrong. If you're attached to JSON because you're working with external API s you don't control, a good place to perform those kinds of actions is in your backend,…

I want to handle a JSON response because I usually return data for multiple page elements. These aren't external APIs, they're requests to the backend server. A simple example is adding a note to a product or order. When you submit it, it gets inlined, and say a visual note counter is incremented. Usually I'll return multiple HTML fragments if it's convenient, but I'll return a data structure if needed.

You can return data for multiple page elements with HTMX too using the "OOB" mechanism.

Re: Let's make the worst Htmx

#79

I really want to try htmx but it specifically prohibits my most common usecases: 1) I want to take a JSON response, create HTML from it, and replace the target element with the generated HTML. 2) Similar to the above, take a JSON response, perform some action, and do nothing to the source element. Is there a plugin to add this? I want to move away from jQuery, and having a small framework to wire up hooks would be us…

Sounds like you are going through similar struggles as a few backend developers I had trying out htmx. Years of muscle memory with returning JSON and letting the frontend (javascript/jquery) to handle the html.

They were making a big deal with this change. In the end the change is rather minimal. The outcome is reduced javascript code and more server side html templates. Pretty much most of the code is now handled on the server side. Just organise the html templates!

Pseudo example

Instead of :-

// returning as Json

[Get]

Response GetUser(int id) {

   var user = getUser(id);

   return ToJson(user);
}

You are just doing :-

// returning as HTML

[Get]

Response GetUser(int id) {

   var user = getUser(id);

   return View("som-user-template", user);
}

I don't know what 'hooks' you need, but whatever they are doing you can move them over to returning/updating section of html on the screen with htmx.

Re: Let's make the worst Htmx

#80

I really want to try htmx but it specifically prohibits my most common usecases: 1) I want to take a JSON response, create HTML from it, and replace the target element with the generated HTML. 2) Similar to the above, take a JSON response, perform some action, and do nothing to the source element. Is there a plugin to add this? I want to move away from jQuery, and having a small framework to wire up hooks would be us…

Sounds like you are going through similar struggles as a few backend developers I had trying out htmx. Years of muscle memory with returning JSON and letting the frontend (javascript/jquery) to handle the html. They were making a big deal with this change. In the end the change is rather minimal. The outcome is reduced javascript code and more server side html templates. Pretty much most of the code is now handled on…

By wiring up hooks I just mean binding a callback to a button that calls fetch() and processing the response (usually replacing HTML, but may modify content and classes on other elements). Basically what I'm looking for is being able to specify a callback (ideally just a global name set from HTML) that will be called with a response object when JSON is returned. I prefer most coding to happen server side, but sometimes client side JS is needed.
Post reply on HN