JavaScript debounce function to limit how often a function runs
JavaScript Dasun Kalupahana 134 views
function debounce(fn, delay = 300) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => fn(...args), delay);
};
}
const onSearch = debounce((e) => console.log(e.target.value), 400);
document.querySelector('#search')?.addEventListener('input', onSearch);
Delays a function until the user stops triggering it for a set time. Use it for search boxes, window resize and autosave so you don’t fire on every keystroke.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
PHP
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
9 min read
Docker
Docker Build Too Slow? 10 Ways to Speed It Up
A slow Docker build usually has one of a few causes: you...
8 min read