Skip to main content
Building Frontends That Feel Instant: The Engineering Behind Perceived Performance

Building Frontends That Feel Instant: The Engineering Behind Perceived Performance

May 2, 2025 3 min read Frontend, Performance, Next.js, React, Web Vitals, Architecture

Building Frontends That Feel Instant: The Engineering Behind Perceived Performance is a Developer Journal article by Ancel Ajanga on https://ancel.co.ke. Speed is not just server response times. How to engineer interfaces that feel instantaneous using optimistic mutations, intelligent prefetching, and layout stability. It focuses on: Even with high-speed 200ms backend APIs, traditional web frontends feel sluggish if every click triggers blocking spinners, layout reflows, or uncoordinated network fetches. Ancel Aja…

Speed is not just server response times. How to engineer interfaces that feel instantaneous using optimistic mutations, intelligent prefetching, and layout stability.

Who this is for

Frontend developers, UI engineers, and technical founders who want their web applications to feel native, responsive, and immediate regardless of network conditions.

Problem

Even with high-speed 200ms backend APIs, traditional web frontends feel sluggish if every click triggers blocking spinners, layout reflows, or uncoordinated network fetches.

Business outcome

Techniques and patterns to achieve zero-perceived-latency interfaces: optimistic updates with automatic rollback, intent-based route prefetching, and cumulative layout shift (CLS) elimination.

Metrics

  • Layout stability through reserved space and skeletons
  • Immediate UI feedback through optimistic mutations
  • Background route prefetching

Speed is not merely a measurement of server response time. You can have an API that responds in an astonishing 80 milliseconds, yet if your frontend application blocks the browser main thread, triggers full-screen loading spinners, and shifts layout elements during hydration, the application will feel slow, clunky, and fragile to users.

Conversely, a thoughtfully engineered frontend can make a 400ms network roundtrip feel completely instantaneous.

In this article, I break down the concrete architectural patterns I use across production applications to engineer interfaces that feel as immediate as native desktop software.

The Problem: The Spinner Anti-Pattern

Most web applications follow an outdated request-response mental model: 1. User clicks a button (e.g., "Add to Favorites", "Mark Complete", "Next Page"). 2. The UI freezes or renders an intrusive spinner. 3. The client waits for the server response. 4. The server responds, the spinner disappears, and the UI updates.

This pattern breaks the user's flow. In the real world, physical switches do not ask you to wait while the electricity verifies its connection; they click immediately. Software interfaces should behave with the same physical confidence.

Architectural Technique 1: Optimistic UI with Ironclad Rollback

Optimistic UI means updating the interface immediately under the assumption that the operation will succeed, while dispatching the network mutation in the background.

To make optimistic UI production-ready, you must pair it with **automatic rollback**:

ypescript
function useOptimisticToggle(initialState: boolean, onMutate: (next: boolean) => Promise<void>) {
  const [isActive, setIsActive] = useState(initialState);
  const [isPending, setIsPending] = useState(false);

  const toggle = async () => {
    const previous = isActive;
    // 1. Immediately mutate UI state (0ms perceived latency)
    setIsActive(!previous);
    setIsPending(true);

    try {
      // 2. Dispatch background network mutation
      await onMutate(!previous);
    } catch (error) {
      // 3. Roll back immediately if the network or validation fails
      setIsActive(previous);
      toast.error("Action could not be saved. Reverting...");
    } finally {
      setIsPending(false);
    }
  };

  return { isActive, isPending, toggle };
}

When a user taps an action, the UI feedback occurs within **16 milliseconds (one frame)**, satisfying human neurological expectations of immediacy.

Architectural Technique 2: Intent-Based Prefetching

Why wait for a user to click a navigation link before requesting the required code and data? - **Hover & Focus Intent**: When a user hovers their cursor over a navigation link or focuses it with a keyboard, there is an average 150ms to 300ms delay before the actual click event occurs. - By triggering a prefetch of the destination bundle and data endpoint on `mouseenter` or `focus`, the resource is already cached in memory when the click happens. Navigation completes instantly without a white flash.

Architectural Technique 3: Eliminating Cumulative Layout Shift (CLS)

Nothing makes an application feel cheaper or slower than content jumping around while images and fonts load: - **Aspect-Ratio Reservoirs**: Always specify explicit container dimensions or CSS `aspect-ratio` for images and dynamic cards before their media assets finish downloading. - **Content-Aware Skeletons**: Use structural skeletons that mirror the exact typography line heights, margins, and grid alignments of the loaded content. Skeletons should hold the space, preventing even a single pixel of layout shift. - **Font Display Swapping**: Use `font-display: swap` with carefully adjusted fallback font metrics to prevent text flashing and line reflows.

Key Engineering Takeaways

1. **Perceived Performance is Real Performance**: Users judge your application by how fast it responds to their physical inputs, not by how fast your database ran an inner join. 2. **Optimistic Updates Require Rollback Discipline**: Never update UI optimistically unless your state management code has an explicit rollback path when the network fails. 3. **Hold Space Before Data Arrives**: Eliminate Cumulative Layout Shift (CLS) by strictly enforcing dimension reservoirs for all asynchronous images, embeds, and dynamic widgets.

Explore my case studies or inspect how these principles are applied across my [portfolio projects](/projects).

Trade-offs

Balancing optimistic UI state against eventual server reconciliation; opting for lightweight inline CSS transitions over heavy client animation libraries.

Challenges faced

Preventing state desynchronization when optimistic mutations fail and communicating retry status to users without disorienting layout jumps.