Group
  • Performance

    Stop my inputs from firing a request on every keystroke

    Debounce and throttle search boxes, autosaves, and live filters so typing doesn't hammer your server.

    • Improve quality
    • Ship faster
    • Beginner
    • General

Free Prompt

My app has inputs that trigger expensive work while the user types: search boxes that hit the API per keystroke, autosave fields that save on every change, live filters that re-query the database continuously. Audit each of these and fix them: 1. Find every input that triggers a network request, heavy computation, or re-render on each keystroke or change event. 2. Apply the right rate-limiting per case: - Debounce search-as-you-type (wait until the user pauses, typically 200-400ms) and cancel in-flight requests when a newer query supersedes them, so responses don't arrive out of order. - Autosave: debounce and also batch; show a clear saving/saved state so users trust it. Handle the case where the user closes the tab mid-debounce (save on blur or beforeunload if the content is dirty). - Sliders, scroll handlers, resize handlers: throttle instead (run at most every N ms) since these fire continuous events where the intermediate values matter less than the latest. 3. Add a minimum query length where it makes sense (no search for one character). 4. Make sure loading states don't flicker: don't flash a spinner for requests that resolve in 100ms; use a small delay before showing loading UI. Don't debounce things that need immediate response (form submit, button clicks). The deliverable is the updated handlers plus a note on how to verify: watch the network tab while typing quickly and confirm only one request fires after the pause.

What This Does / How This Helps

This audits every input that fires requests or heavy work per keystroke and applies debouncing, throttling, request cancellation, and minimum query lengths. A search box that hits your API on every keystroke turns one user typing 'postgresql' into ten database queries, most of them discarded. Multiply by real users and your server spends its life answering queries nobody waited for. It also produces visible bugs: responses arriving out of order so the results show a stale query's data. This is a small change with an outsized effect on both server load and perceived speed.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts