Hacker News new | ask | show | jobs
by Draiken 928 days ago
Use HTMX and you'll be surprised how much you don't need JS for (or to be more accurate, very little JS).

Rails especially is very good for this with partials. Use ERBs (or Haml, Slim, etc) and it's an absolute bliss with the added benefit of easy caching.

Stop duplicating state. Stop duplicating logic. Maybe in the future when your app needs 5 different clients, it makes sense to only have an API. But let's not pretend that should be the default!

I still cry every time I see a new application using GraphQL to have literally one client which is simply serving HTML with a bloated JS framework. The whole premise of it was to be flexible for multiple frontends. Come on folks, YAGNI.

2 comments

I used HTMX since the intercooler days [0] but the stuff you can make is rather limited. Also you still need the JS to deal with a11y things like expanded state (or hyperscript, apparently).

If you have a lot of components to implement, everything requires thinking. Example: You want to add a repeat field to a form. Easy, get the input from an endpoint, and append. Done? No, how do you remove a field? Add a line of JS, simple! Drag and drop if the order needs to change? Let's add a dependency! [1]

I really love it for simple applications though. Resist implementing a complicated menu, live notifications, an editable data-table and such non-web-native things and you can create the fastest CRUD app ever.

And you will need another client (don't YAGNI me on this one, burned too many times by people not caring about endpoint design), but that's not really an issue if your view model does not contain non-public data (it shouldn't), as you can convert it to JSON at the same endpoint (respect the accepts header) and call it an API.

[0]: https://intercoolerjs.org/

[1]: https://htmx.org/examples/sortable/

Rails with turbo and stimulus is amazing. Very similar to htmx and phoenix liveview. Stimulus lets you make a really minimal web framework for ui elements that are mostly defined as ruby components, and turbo lets you to use erb without whole page reloads. Whole responsive web apps with a dozen lines of js, its great.
What do you mean by UI elements defined as ruby components? Are you referring to ViewComponents or something else?
Yeah you can define viewcomponents in ruby. Have them rendered based on stimulus code. Turbo lets you do updates without full page reloads, viewcomponents make much more reusable and flexible ruby based components than pure erb, and stimulus handles front end state. I rewrote a medium size react + graphql page with this and thr code base was literally 1/10th the size