Hacker News new | ask | show | jobs
by aitchnyu 894 days ago
Wonder if there is there anybody who is making an offline app with request-reponse with html(with HTMX) and a virtual server defined in a service worker?
3 comments

This is a great question.

I love htmx but in situations that have to work offline I can't use it. Would be a great hack to be able to just run your server code in a worker.

> Would be a great hack to be able to just run your server code in a worker.

This is exactly why some people build heavy offline-first SPAs in JS. HTMX tries to avoid this entirely. Conceptually (seen from the perspective of HTMX), it makes zero sense to put the server code in a worker and run a client-server architecture in the client‘s browser.

This would be an over-engineered thing that HTMX explicitly tries to avoid in the first place.

> This would be an over-engineered thing that HTMX explicitly tries to avoid in the first place.

Yes, this is where I think a lot of folks who moan about "bloated JS frameworks", etc. really are just complaining they can't use their favorite (or only) language for web UI development.

I made an app doing this with an HTMX-like library with a total of 100 kB minified/zipped code. Not bloated at all. The code to make it work is about 10 kB. The rest is the code for the actual app.
I'm not sure "zero sense" is true. An app designed around REST and hypermedia imposes sensible constraints, like how you handle state, navigation, etc., and this can still yield plenty of benefits.
Yes, I've done this and the code is really simple to understand compared to a SPA.

https://github.com/jon49/Soccer

I am not sure if I understand the definition of offline here. HTMX has graceful degradation options. What else could you do when the client is offline?
There are many apps that work when the user is entirely offline and HTMX is not a good option if that is a key requirement of your app.

Figma is an example.

I've done this. HTMX offline-first is an elegant way to build apps.
Should work if the worker behaves like a traditional backend and return/proxies html pages rather than JSON?
I'm working on a server/backend for htmx that's intended to run as a local service beside the browser. In theory you could do this with any server stack that is self host-able. My goal is to produce a single binary with no external service dependancies. I'm using Go, and a lot of the components are readily available, e.g. self updating local service, replicated database, etc. It's easy to cross-compile for different target OS and architectures. As an alternative to building everything into the browser, and assuming you're able to run a separate process, this approach makes a lot of sense to me. It would be great if Go had something similar to Deno's permission management though...
Yes, here is one. https://github.com/jon49/htmx-todomvc

I use this pattern for all my personal apps. I use my own little htmx-like library though. But wouldn't be that hard to swap in HTMX.