Local First Htmx

elijahm.com

122 points by srid 3 days ago


oldestofsports - 3 days ago

HTMX is neither a meme nor is it anti-javascript, it is literally written in js.

It does not aim to remove js from your code, it simply adds more features to HTML by default, like making any element able to trigger an web request.

When you write a real world app with HTMX, you inevitably end up writing some js, which is totally fine.

kubafu - 3 days ago

Big fan of htmx here, so thanks for opening my eyes to a new way of using it with service workers.

But man, 10MB Go WASM download? That's a no go. It's not only about downloading it but executing on a clients machine over and over again. But I guess you can handle those requests perfectly fine just in service worker using pure JavaScript.

logankeenan - 2 days ago

It's really cool to see someone else gravitate toward this idea. I think there might be some real potential in the future. I wrote about a similar idea in 2022 [0] and 2023 [1]. The service worker approach was heavily inspired by Richard Anaya's work [2]. HTMX migrating to fetch [3] makes this even easier. I had to create a xhr-fetch-proxy [4] to intercept requests with htmx today. I'm not the author, but would be happy to answer any questions.

[0] https://logankeenan.com/posts/a-rust-server-app-compiled-to-...

[1] https://logankeenan.com/posts/client-side-server-with-rust-a...

[2] https://github.com/richardanaya/wasm-service

[3] https://news.ycombinator.com/item?id=45803358

[4] https://github.com/logankeenan/xhr-fetch-proxy

pickpuck - 3 days ago

I built something with Service Workers a few years ago. It's similar in concept, but I never got around to syncing with a server.

Instead of a WASM backend, I used react-dom/server to generate the HTML.

https://github.com/michaelcpuckett/listleap?tab=readme-ov-fi...

quicksilver03 - 2 days ago

I have an issue with

    The geneal idea of HTMX is that your HTML will be rendered by the backend — à la Server Side Rendering.
To me this phrase makes no sense, what's the thought process behind this meaning of "render"? The only place HTML is "rendered" is in a browser (or in a user agent, if you prefer).
librasteve - 3 days ago

Really enjoyed this article … thanks for opening my mind wider.

In case anyone thinks this idea is serious, my strong like of vanilla HTMX came from the realizations that (i) state management can revert to the ur-web model and avoid all the complexity of browser / server state synch and (ii) I can use anything I damn well like on the server (I wrote https://harcstack.org to optimize for expediency).

flashgordon - 2 days ago

Wow I am loving this. I had a very related question on the htmx discord (ie can we load content from "any function" instead of an endpoint. My use case was that I used the FE (in typescript) in a very stateless way and had most of the logic driven by a go-wasm binary (the binary was pretty much the "M" and "P" in MVP). When I saw the Wasm binary here in the post it gave me a bit of relief. Cant wait to see this direction take off!

dlisboa - 2 days ago

Local first is really relevant if you have the potential of users losing connectivity or is building some sort of collaborative workflow and want updates to happen automatically (like Linear or Google Docs).

Latency is not a real issue with SSR apps, there are a bunch of solutions to place servers and data closer to your users (within a few tens of ms). Plus you can prefetch and cache content very easily without using service workers. That’s not the reason Jira or GitHub feel slow; in fact GitHub was quite fast a few years ago when all it did was render pages from the server.

scuff3d - 2 days ago

I'm not a web dev but isn't the initial page load going to be a bitch if you have to ship a whole ass web server with it?

righthand - 3 days ago

The WASM component just seems like a way to avoid writing models? Or is it demonstrating that you can run your server in the browser? Why is WASM needed then if it's just handling simple internal requests. WASM adds a layer of Golang which would be nice if the server needed to be portable from the local, but then why run the server locally at all if you need it in remote contexts? If you're trying to build a simple local JS app, why not just write it all in JS?

BinaryIgor - 2 days ago

Interesting article, but isn't the main HTMX use-case mostly where you want to make server do most of the work, that is Remotely? As you literally render its responses directly - HTMX pages and fragments - instead of doing HTML -> JSON -> HTML gymnastics. Using paradigm of this kind to build local/client-first apps sounds weird.

aidenn0 - 3 days ago

So far, all of the comments are taking this far too seriously. It's literally just: "htmx is supposed to be great" and "Local first is supposed to be great" so lets combine them in the dumbest way possible.

euroderf - 2 days ago

This architecture looks perfect, for the locally inclined. Waiting for episode 2.

fud101 - 2 days ago

why we even need a backend. just run it in the browser. is there a framework for that?

indatawetrust - 3 days ago

[dead]