New releases

Hotwire Club tooling is now open-source

Explore the agentic skills pack and the MCP server for building assistant workflows.

Stimulus - Video Progress Tracker with LocalStorage

Store ephemeral user state like video playback progress in localStorage

View Solution on Patreon
Stimulus - Video Progress Tracker with LocalStorage

Premise

A lot of UX leverage lies in the way applications manage ephemeral user state. The traditional approach to store such data would be to reach for server side sessions. However, sometimes this is overshooting the target because it leads to more complexity on the server side, having to (de)serialize data structures and manage rehydration. Often, client-side localStorage provides a simpler alternative.

Starting Point

We are going to experiment with localStorage using an example containing three <video> elements on a page:

https://stackblitz.com/edit/stimulus-video-progress-tracker?file=index.html%3AL41

The goal is to store the playing progress for each video and restore it on page reload. Here’s a GIF showing this in action:

Video progress stored and restored after page reload

Challenge

In a video-progress Stimulus controller, write two actions:

  • recordProgress for storing the current time for each video in localStorage
  • #seekToProgress to restore the current time upon connect

As you can see, #seekToProgress is already called whenever the controller is connected. What’s missing is to fire the correct event and update the storage entry. For this, wire up it up in data-action:

https://stackblitz.com/edit/stimulus-video-progress-tracker?file=index.html%3AL49

Tip: Look at the Video Embed element docs for some clues.

Teasers

Suppose you want to store sensitive data in localStorage that you don’t want anyone to tamper with. What are your options?

This is The Hotwire Club

52 hands-on challenges with detailed solutions, published biweekly since 2023. Subscribe to access all solutions and join the Discord community.

Subscribe on Patreon

More from

Stimulus - Promise-Returning Outlet Methods
22 July 2026

Turn a Stimulus controller into an await-able API by returning a promise from an outlet method and resolving it from a dialog's button handlers.

Stimulus - Optimistic Toast Notifications with Auto-Save
26 May 2026

Build an auto-save form that fires a toast notification the instant it submits, not when the server responds, using Stimulus outlets.

Turbo Frames - Error Boundaries
28 April 2026

Build a reusable Stimulus controller that catches Turbo Frame failures and shows elegant error states with retry - inspired by React's Error Boundaries.

Cookies
essential