#performance Clear
Tags #utils #browser #performance #array #async #dom #objects #pattern #events #format #concurrency #http #ui #advanced #fetch #url #string #functional #cache #files #crypto #promise #intl #observer
JavaScript Debounce
Delays invoking a function until after a specified wait time has elapsed since the last time it was called. Essential for search inputs, resize handlers, and any event that fires rapidly — prevents excessive function calls and improves performance.
JavaScript Throttle
Ensures a function is called at most once per specified time interval, no matter how many times the trigger fires. Ideal for scroll listeners, mousemove handlers, and window resize events where you need regular updates but not every single frame.
JavaScript Memoize Function
Caches the result of a pure function keyed by its serialised arguments. On repeated calls with the same inputs the cached value is returned instantly, skipping expensive computation. Supports single and multi-argument functions via JSON key serialisation.
JavaScript Intersection Observer (Lazy Load / Reveal)
Uses the IntersectionObserver API to trigger a callback when elements enter the viewport. The reveal pattern adds a visible class to animate elements as they scroll into view. The lazyLoad pattern loads images on demand by swapping data-src to src. Much more performant than scroll event listeners.
JavaScript Rate Limiter (Token Bucket)
Implements a token-bucket rate limiter that allows a burst of calls up to a maximum capacity, then replenishes tokens at a steady rate. Useful for throttling outbound API requests, user-facing actions, or any operation where you need to allow occasional bursts without exceeding a sustained rate.
JavaScript Worker Pool (Web Workers)
Manages a pool of Web Workers for CPU-intensive tasks (image processing, crypto, parsing). Distributes tasks across available workers using a round-robin strategy and returns a Promise per task. Falls back gracefully to inline execution in environments where workers are unavailable.