Todas las publicaciones
post10 de abril de 2026

Throttle — Limita la Tasa de Llamadas

#javascript#performance#throttle
Throttle — Limita la Tasa de Llamadas — slide 1
javascript
function throttle(fn, limit) {
  let inThrottle = false;
  return function(...args) {
    if (!inThrottle) {
      fn.apply(this, args);
      inThrottle = true;
      setTimeout(() => (inThrottle = false), limit);
    }
  };
}

const onScroll = throttle(() => {
  updateParallax();
}, 16);  // ~60fps

window.addEventListener('scroll', onScroll);