Course Overview
Locked video preview

Paid video

Please purchase the course to watch.

Modern hypermedia

Surgical updates

Here is a summary of the video transcript:

  • Clickable Article Cards with Datastar
    The video demonstrates how to make entire article cards clickable using data-on with a click event. Instead of wrapping cards in anchor tags, a GET request is issued via Datastar, triggering navigation through server-sent events (SSE). A pointer cursor is added to improve UX.

  • Partial Page Updates for Pagination
    Pagination is refactored to update only the latest articles section instead of reloading the entire page. A dedicated articleCardsGrid component is introduced, and updates are targeted using consistent element IDs so Datastar can morph the correct DOM node.

  • Backend Integration with Datastar SSE (Go SDK)
    A new controller method is created to return only the article grid using Datastar’s Go SDK. Server-sent events are used to patch specific elements in the UI, and a new route is registered to handle these partial updates.

  • URL State Management
    Since partial updates do not automatically modify the browser URL, history state is manually updated using window.history.pushState. On the backend, replaceURL is used to ensure pagination state persists across refreshes and navigation.

  • Signal-Based UI Updates
    A currentPage signal is introduced to dynamically display the active page number. Signals are defined higher in the DOM and updated from the backend using marshalAndPatchSignals, allowing UI elements to change immediately without waiting for full request completion.

  • Dynamic Page Metadata
    The hardcoded total page count is replaced with backend-provided pagination metadata. The UI now reflects accurate page numbers (e.g., “2 out of 2”) and remains consistent after refreshes.

  • Advantages of Server-Sent Events
    The approach highlights how SSE enables incremental UI updates, multiple sequential patches, and backend-driven state changes. This allows efficient, fine-grained reactivity without full page reloads.