gitwtfhub

wtf is debounce?

sindresorhus/debounce — explained in plain English

Analysis updated 2026-08-02 · repo last pushed 2026-03-11

850JavaScriptAudience · developerComplexity · 1/5MaintainedLicenseSetup · easy

TL;DR

Debounce is a tiny JavaScript helper that delays running a function until calls stop coming in, preventing it from firing too many times in quick succession.

Mindmap

mindmap
  root((repo))
    What it does
      Delays function calls
      Prevents rapid repeat runs
      Resets timer on new calls
    Features
      Immediate mode
      Cancel pending calls
      Check if pending
      Force trigger on demand
    Use cases
      Window resize handling
      Search box input
      Autosave features
      Stop double clicks
    Tech stack
      JavaScript
    Audience
      Web developers
      Vibe coders

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Prevent a search box from querying the server on every keystroke by waiting until the user stops typing.

REASON 2

Stop accidental double-submissions on buttons by using the immediate mode to fire once and ignore extra clicks.

REASON 3

Wrap a window resize handler so it only runs once after the user finishes dragging the browser edge.

REASON 4

Delay an autosave function until the user pauses editing so it does not fire on every keystroke.

What's in the stack?

JavaScript

How it stacks up

sindresorhus/debouncejustjavac/chromesnifferplusnamastedev/namaste-react
Stars850847858
LanguageJavaScriptJavaScriptJavaScript
Last pushed2026-03-11
MaintenanceMaintained
Setup difficultyeasyeasyeasy
Complexity1/51/51/5
Audiencedeveloperdevelopervibe coder

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

Install with npm and import the single function, no configuration or external dependencies required.

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

Wtf does this do

Debounce is a small JavaScript utility that prevents a function from running too many times in quick succession. Instead of executing every time it's called, it waits until a specified amount of time has passed without any new calls before actually running. This is useful when something triggers frequently and you only care about the final action. The classic example is handling browser window resizing. Without any protection, a resize function might fire dozens of times per second as a user drags the edge of their browser window. With debounce, you wrap that function and set a delay of, say, 200 milliseconds. Now the function only runs once, 200ms after the user stops resizing. Each new call during the wait period resets the timer, so the function waits until things settle down. Anyone building a web interface where user actions fire repeatedly would find this handy. Beyond window resizing, common use cases include search boxes that query a server as you type, autosave features that should wait until you stop editing, and button clicks where you want to prevent accidental double-submissions. There's an "immediate" mode that runs the function right away on the first call rather than waiting, which is specifically designed to stop double-clicks on buttons. The tool also provides a few control methods on the wrapped function. You can check whether a delayed execution is still pending, cancel a scheduled run entirely, force it to execute immediately if one is waiting, or trigger it on demand while clearing any existing timer. The project is intentionally minimal and focused, doing one thing cleanly without extra complexity.

Yoink these prompts

Prompt 1
Write a debounce utility in JavaScript that delays a function call until a specified time passes with no new calls, and also supports an immediate mode that runs on the first call and ignores subsequent calls.
Prompt 2
Show me how to use a debounce function to prevent a search input from hitting the server on every keystroke, only querying after the user stops typing for 300ms.
Prompt 3
Create a debounced button click handler that runs immediately on the first click and blocks any duplicate clicks for the next 500 milliseconds.
Prompt 4
Implement a debounce function that returns a wrapper with cancel, flush, and pending methods so I can check whether a delayed call is still waiting or force it to run immediately.

Frequently asked questions

wtf is debounce?

Debounce is a tiny JavaScript helper that delays running a function until calls stop coming in, preventing it from firing too many times in quick succession.

What language is debounce written in?

Mainly JavaScript. The stack also includes JavaScript.

Is debounce actively maintained?

Maintained — commit in last 6 months (last push 2026-03-11).

What license does debounce use?

Use freely for any purpose, including commercial use, as long as you keep the copyright notice.

How hard is debounce to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is debounce for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.