Debounce Window resize callbacks in JavaScript

It's important to debounce the calls you do when listening to the resize window event. Otherwise your function could be called hundreds of times, slowing the user's performance.

The debounce function

We need the black magic first.

Your code here

As you can see we're passing a callback function and a timeout. You can experiment with different values to make it look more real time.


About Rick

Senior Front-end Software Engineer from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

Leave a Reply

Add <code> Some Code </code> by using this tags.