Jquery Autocomplete local data or AJAX request


I am using this plugin of autocomplete, my doubt is that I do not decide whether to provide the list of elements to filter via AJAX or store it locally, because if it is via AJAX you will be making queries to the database of type LIKE "%queryDelUsuario%" that from what I understand is very slow each Once the user types in the search engine. But I do not know how convenient it is to store it locally when the item number increases to 100,000 (just to give an example).

Which of the options is more optimal when the number of elements tends to be increasingly higher?

asked by Genarito 02.03.2017 в 17:33

1 answer


You could store it locally when loading the page all the names that you consider of the table, and pass it to what is called sessionStorage, in the following way. (sessionStorage is a local storage that has a maximum of 5mb of writing)

When loading the page, bring data from the bbdd, according to the columns that the query does, to this we will place a variable "data".

then with jquery you pass this data to the sessionStorage in the following way:


Data in this case is a json, which you can then consult directly from the sessionStorage that is on the client side now only.

If you need to extract this information, just:

datosAlmacenados = sessionStorage.getItem("datosAlmacenar");

now that you have it in json you can search it if it exists, and if it exists, you do the search in the bbdd

PS: To eliminate the sessionStorage, just:


I hope I have helped you: D

answered by 27.03.2017 / 19:31