开发者

Live search optimisation in Javascript

开发者 https://www.devze.com 2023-04-07 15:30 出处:网络
I have some code in Javascript (not jQuery, unfortunately) at the moment that performs a live search on a database, depen开发者_StackOverflowding on what the user enters.

I have some code in Javascript (not jQuery, unfortunately) at the moment that performs a live search on a database, depen开发者_StackOverflowding on what the user enters.

The problem is, if you type quickly, it'll still be performing the search from the last keystroke and this can add up to a delay of anything up to ten seconds.

I know I should cache this information, and it's definitely something I'd love to do soon (along with implementing jQuery) but for now I was wondering if there was any way at all to speed this up?

I've already limited the number of rows the search returns to 20, and have made sure the search doesn't run unless there are 3 or more characters.

Thanks


Make the ajax call trigger 1 or 2 seconds after the user stopped typing.

If you need code for this let me know in the comments.


You can check if there's already a request running. If so, abort it. (currentRequest.abort())

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号