Debounce and Throttle
Two opposite strategies for limiting how often a handler runs against a rapid stream of events.
Debounce and Throttle both limit how often a function runs in response to a rapid-fire event — a keystroke, a scroll, a resize — but they trade off in opposite directions. Debounce waits for a pause: it delays the call until events stop arriving for a set interval, and each new event resets the timer. Type five characters quickly into a search box wired to a debounced autocomplete request, and only one request fires, after the last keystroke plus the delay — not five. It's the right tool when only the final state matters and intermediate ones are noise.
Throttle does the opposite: it guarantees at most one call per fixed interval, regardless of how many events arrive in between, firing on a steady cadence for as long as events keep coming. A scroll handler updating a progress bar wants throttling, not debouncing — the user needs to see the bar move during the scroll, not only once it stops; debouncing that handler would make the bar sit frozen until the user finished scrolling entirely.
The failure mode for each is predictable once you know which one you picked wrong. A debounced scroll handler feels laggy and unresponsive, firing only after motion stops. A throttled search-as-you-type feels chattery, firing a request on every interval tick while the user is mid-word, wasting requests on states nobody needed. Neither is a general-purpose fix for "too many events" — the choice is a statement about which events in the stream are the ones that matter.
Both exist to protect the same resource a naive Optimistic UI update or WebSocket send would otherwise hammer: a network request, a re-render, or any handler whose cost scales with call count rather than with the final result.
See also3
Optimistic UI
Updating the UI as if a server request has already succeeded, before the server has actually responded.
Web Platform21 connections
WebSocket
A persistent, full-duplex connection between browser and server, replacing repeated request-response with an open channel.
Web Platform16 connections
Performance Budget
A committed numeric ceiling on a page's cost, enforced automatically.
Web Platform26 connections
Related6
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from9
- AutocompleteData & Content
Suggesting completions while someone types, which needs prefix-friendly indexes, ranking by likely intent, and careful handling of latency, typos, and accessibility.
- File WatchingSystems & Tooling
How programs learn that files changed, by polling or by kernel notification interfaces such as inotify and FSEvents, and the many ways those notifications get lost, delayed, or exhausted.
- Frame PacingGraphics & Rendering
How evenly frames are delivered over time, which shapes perceived smoothness more than average frame rate does.
- HysteresisMatter & Energy
The dependence of a system's state on its history as well as its present input, seen in magnets, rubber, and freezing water, and built deliberately into thermostats and switches so they don't flicker at a threshold.
- Long TaskWeb Platform
Any stretch of main-thread work over 50 milliseconds, during which the page can't respond to input, and the techniques for breaking such work up.
- Optimistic UIWeb Platform
Updating the UI as if a server request has already succeeded, before the server has actually responded.
- Pointer EventsWeb Platform
The browser's unified model for input from a mouse, a finger, or a pen, delivering one set of events with details such as pressure and contact size, which replaced separate and incompatible mouse and touch event systems.
- requestAnimationFrameWeb Platform
The browser callback that runs once per display frame just before paint, which is the right clock for visual work and stops entirely when nothing is being displayed.
- Web WorkerWeb Platform
A background thread for running JavaScript off the main thread, with no access to the DOM.