Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Javascript Unlocked

You're reading from   Javascript Unlocked Improve your code maintainability, performance, and security through practical expert insights and unlock the full potential of JavaScript

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781785881572
Length 182 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
 Sheiko Sheiko
Author Profile Icon Sheiko
Sheiko
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

JavaScript Unlocked
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Diving into the JavaScript Core FREE CHAPTER 2. Modular Programming with JavaScript 3. DOM Scripting and AJAX 4. HTML5 APIs 5. Asynchronous JavaScript 6. A Large-Scale JavaScript Application Architecture 7. JavaScript Beyond the Browser 8. Debugging and Profiling Index

Event handling optimization


It must have happened to you while writing a form inline validator that you run into a problem. As you type it, the user-agent keeps sending validation requests to the server. This way you might quickly pollute the network with spawning XHRs. Another sort of problem that you may be familiar with, is that some UI events ( touchmove, mousemove, scroll, and resize ) are fired intensively and subscribed handlers may overload the main thread. These problems can be solved using one of two approaches known as debouncing and throttling. Both functions are available in third-party libraries such as Underscore and Lodash (_.debounce and _.throttle). However, they can be implemented with a little o code and one doesn't need to depend on extra libraries for this functionality.

Debouncing

By debouncing, we ensure that a handler function is called once for a repeatedly emitted event:

  /**
   * Invoke a given callback only after this function stops being called `wait` milliseconds...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £13.99/month. Cancel anytime
Visually different images