Javascript In Rails

Without going full-on with a Rails API backend, and pure React/VueJS frontend, there’s still some options to add interactivity and responsiveness to the frontend when moving on from jQuery.

  • Stimulus JS (web) is a BaseCamp extraction, doesn’t do any rendering, just exists to provide some really straightforward interaction. Plays well with asset pipeline & turbolinks.
    • If you want to supercharge it, check out StimulusReflex or Motion for high-performance reactive components, powered by Stimulus and Websockets.
  • react-rails also works with asset pipeline/webpacker, and gives you a straightforward way to render react components from your views. Works best with smaller components.
  • Alpine JS directly bills itself as a minimal alternative to Vue/React, can be written inline or extracted to helper methods. Can be readily used as a raw javascript include (via CDN or asset pipeline) to be rails-friendly without bringing in NPM/webpack unnecessarily.
  • Inertia is “the glue that connects” server-side and client-side frameworks.

Books