What Is Throttling ?
“ In Programming Throttling Is Technique To Limit The Number Of Execution In Given Time.”
Explanation Of How Throttling Works
For example, we call a function when the user clicks the button. if a user clicks button 500 times, function will be called 500 times. but what if we want to limit the function calls. for example, no matter how many times a user clicks the button, we want to call the function only certain number of times.in such situations, we can use a technique called throttling.
Why We Need Throttling
Executing heavy operation every time degrades the performance of the software. Throttling prevents execution every time a call is made. Only executes function if limit matches. That can significantly improve performance & you can give a better user experience.
Explanation Of Above Example
In the above example, if the user clicks the button we call the HeavyTask function. but if the user clicks again then we call the HeavyTask function only if the time difference between the last call & the current call is more than 1 second. so no matter how many times the user clicks the button we call HeavyTask once every 1 second.
When To Use Throttling Or Some Use Cases Of Throttling
- Network request
- Scroll events
- Event Handling
- Gaming Features
Implementing throttling in jquery
Implementing throttling in lodash
Implementing throttling in underscore
So in Short throttling limits the number of execution. I hope the concept Of Throttling is now clear to you. If you have any doubt, suggestions or feedback feel free to comment below or contact me on my email.