4 ms·
SPAs obviously have some positive sides, i.e. state management, but that goes with a price of increasing complexity, especially if server-side rendering is requ
by can3p 6y ago
SPAs obviously have some positive sides, i.e. state management, but that goes with a price of increasing complexity, especially if server-side rendering is required.
In majority of cases, especially when building tools like back offices it's not what you want, you just want to be able to render forms, tables and save them in a convenient way.
I've found turbolinks + simulus.js combo to work surprisingly well. Actually, I use the only one stimulus.js controller in majority of cases - one that makes an ajax request and reloads the page (with the help of turbolinks) on success. If page load time is fast enough, the use experience is the same as if you would change the dom with js manually. Of course the requirement is that reloaded page reflects the changes.
Other stimulus.js controllers are there for the cases that don't fit into aforementioned pattern. That sounds primitive but can take you a really long way without turning your js into a a monster.
In addition to that you don't need to care about the routing, html validation just works, you can wrap existing html components and even inject react apps here and there if you really need to.
[EDIT] Forgot to say - this approach does not force any language or architecture on the server-side
- danjac 6y agoI'm really liking turbolinks+stimulus. While I'd probably still reach for Vue for more intricate work there is a lot of mileage you can get out of turbolinks with a small set of stimulus controllers. It's not just for Rails either: the Changelog people use Turbolinks with Elixir/Phoenix [1] for their site, including an audio player (although not with Stimulus), and I used it for a recent side project with Django [2]. [1] https://github.com/thechangelog/changelog.com https://github.com/thechangelog/changelog.com [2] https://demo.localhub.social/ https://demo.localhub.social/