pausing for input - javascript
I write websites and connect them to databases as part of my job, and I've found this little trick helps out quite a bit when I'm writing some javascript which tries to autofill or search while typing.
function KeyHandler()
{
if(!(typeof nagle == "undefined")){clearTimeout(nagle);} // if there's a timeout set on SendKeys, clear it...
nagle = setTimeout("SendKeys()",250) // set new timeout to 250ms....
return false;
}That little bit of script creates a function which can be called on every keypress event, and after the last key is pressed, it will wait 1/4 of a second before running the function "sendkeys".
It doesn't have to be related to sending data to a server though, you can use this with other scripts, like if you want to filter a table or something else.
Oh, and I chose the word 'Nagle' because it was part of a larger script which implemented John Nagle's
idea of waiting a moment before data is sent, with the intention of reducing the overhead of single keypresses. His idea was to reduce the amount of data sent over a network, and my idea is to reduce the number of queries to my server.