Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2012 03:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4273803 to your computer and use it in GitHub Desktop.
Save anonymous/4273803 to your computer and use it in GitHub Desktop.
why search suggestion was failing on touch
The problem was that setInterval would fire off multiple duplicate requests per
second. On each subsequent request would abort the previous request in
processRequest. ajaxCache would store the arguments in the first requests and
not serve the subsequent ones. To handle this, we keep track of the previous
search and only send an ajaxCache request if the search is different from the
previous one. This prevents multiple duplicate requests from blocking each
other by only having one of them be able to make the request.
There is still the problem of backspacing in search suggestions. On each letter
I add to my search query, an ajaxCache request is fired off. As I add more
letters to reach my desired query, ajaxCache remembers each substring of the
query as I typed it. And process request is aborting these requests as I type
more letters. So, when I backspace my request, ajaxCache finds the search
queries in its cache, but actually these queries were aborted. It thinks it has
the data, but it doesn't since it was aborted, so it returns nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment