Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6004801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:18:50+00:00 2026-05-23T01:18:50+00:00

I have a web-based search input. At each onkeyup event, an async request is

  • 0

I have a web-based search input. At each onkeyup event, an async request is made, from the client with JavaScript, to a PHP document that returns the search response – then the JS takes the search response and writes it to the client. This part works fine.

However, my issue is when a user types their search term faster than the system can respond.

Let’s say a user – that types fast – is doing a search for the word super. The user types s (and a search is done for s), while the search is being performed and written for s the user types u, and now a search for su is queued up. Then, this very fast typing user types a p, while the initial search for s is finishing up, and now searches for su and sup are queued.

If a user types slowly, there is no issue and my search tool can respond to each keyup without having to queue up search requests. However, if a user types very fast, they will see several search result refreshes flash before them after they finish typing their search term because the script is finishing up items in the queue.

How could I improve my code to improve the user experience?

For example, how would you script this so that any queued items, other than the last one made are dropped?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:18:51+00:00Added an answer on May 23, 2026 at 1:18 am

    You can do this with a single timeout (called debouncing):

    “Debouncing means to coalesce several temporally close signals into one signal.”

    var timer;
    function keyup() {
      clearTimeout(timer);
      timer = setTimeout(function() {
        search(this.value);
        timer = null;
      }, timer ? 50 : 1);
    }
    

    This code means that if the user is typing too fast (delta <50ms in this case) the action won’t queue up, but the newest always overwrites the previous ones.

    There is another approach (called throttling):

    “Throttling is the reduction in rate of a repeating event.”

    var timer;
    function keyup() {
      if (!timer)
        timer = setTimeout(function() {
          search(this.value);
          timer = null;
        }, 100);
      }
    }
    

    Finally you can fetch more data at a time to get around latency issues.
    See this post to see how Flickr does it: Building Fast Client-side Searches

    Also make sure to use some kind of caching (APC/memcache) depending on how frequently your data changes. This can greatly reduce stress on your database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web-based application which is very highly reliant on jquery / javascript,
I have a client of my web based application who heavily uses the data
I have a web-based documentation searching/viewing system that I'm developing for a client. Part
I have a web-based application that notifies users of activity on the site via
I have a web-based system built with user login data based on session variables.
I have a web based (perl/MySQL) CRM system, and I need a section for
I want to have a web based admin to upload, delete files and folders
Hopefully this will not spark a religious war... We have a web based app
I have heard that web-based chat clients tend to use networking frameworks such as
I have an idea for a web-based service. The implementation is very complex. There

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.