What's the best way to implement AutoComplete in the server?

前端 未结 2 518
自闭症患者
自闭症患者 2021-02-03 14:53

This question is easy people. Make autocomplete beautiful in the client side of a web app is simple. There are a lot of plugins.

But, in the backside, in the server side

2条回答
  •  既然无缘
    2021-02-03 15:44

    You say in the comments that "It's a small dataset" of key words. Thus, it might be appropriate to have the client request the whole list as soon as the user starts typing into the field, then have the JavaScript respond to changes in user input on the client side.

    That's one server hit per field per page (and only if the user types in the field), and you can cache it on the server so it rarely has to hit the DB.

    Edit: Caching on the server is a big win because the list is the same for every request and for all users, but even better, this means you can cache the list in the client's browser by using an Expires or Etag header with a suitable period in the response. Thus the user can get unlimited autocompletion for just one (well-cached) server hit for the entire period of the browser cache.

提交回复
热议问题