Search

2/19/2013

Debounce and Throttle: a visual explanation | Drupal motion

Debounce and Throttle: a visual explanation | Drupal motion - debounce是只會fire那最後一次, throttle會regulate才每固定 n 秒 fire 一次

Use cases for debounce Use it to discard a number of fast-pace events until the flow slows down. Examples: When typing fast in a textarea that will be processed: you don't want to start to process the text until user stops typing. When saving data to the server via AJAX: You don't want to spam your server with dozens of calls per second. Use cases for throttle Same use cases than debounce, but you want to warranty that there is at least some execution of the callbacks at certain interval If that user types really fast for 30 secs, maybe you want to process the input every 5 secs. It makes a huge performance difference to throttle handling scroll events. A simple mouse-wheel movement can trigger dozens of events in a second. Even Twitter had once problems with scroll events, so learn from others mistake and avoid this easy pitfall.

沒有留言: