Time-ago formatting with Stimulus (no heavy date libs)

544
0

For small UX touches like “3 minutes ago”, I don’t want to pull in a giant date library. A Stimulus controller can use Intl.RelativeTimeFormat plus a lightweight difference calculation. The server renders the ISO timestamp (via time_tag), and the controller turns it into a relative string on connect. It stays correct across Turbo page changes because the controller reconnects. For longer-lived pages, you can also update on an interval. The main thing is to keep a fallback for no-JS: the raw timestamp is still in the HTML and accessible. This pattern is also helpful for localized UIs since Intl handles language and pluralization.