6 ms·
Just add a short delay between the keypress & the search/url push, and add a check to see if the query is the same. If after a ~second or so the query is the sa
by danielsoneg 15y ago
Just add a short delay between the keypress & the search/url push, and add a check to see if the query is the same. If after a ~second or so the query is the same, do the search and update the URL.
- tripzilch 15y agoYes please! This was the first thing I noticed, maybe my netbook is too slow but I do a lot of coding on the little thing. The way I solved this in a similar auto-complete app was using a setTimeOut to prevent updating or requesting data unless no key had been pressed in the last 0.2 seconds or so: var updateId = 0; function searchKeypress(e) { if ((e || window.event).keyCode == 13) { updateCookie(radioStations.selected); document.location = radioStations.selected.links[0].url; } clearTimeout(updateId); updateId = setTimeout(searchUpdate, 200); } Disclaimer: this piece of code is about 4 years old and as you can see it doesn't even use jQuery, but I trust it demonstrates the principle well enough.
- pdaddyo 15y agoI'd use underscore.js's _.debounce method, simples!