Slow loading jQuery autocomplete
Hi I am creating an internal application for my company using jQuery autocomplete and I find it starts very slowly. My guess is that the neck of the bottle is possibly adding its elements to the DOM, since it appears to be significantly faster after the first request. Does anyone know how to preload these elements on page load and not do it the first time the user starts typing?
source to share
If you don't need to use ajax calls to fetch data and your autocomplete list is not too big, you can pass the autocomplete data from an array of js objects.
Let's assume you have data like this (which you create as early as possible / can):
var data = [{"n":name, "p":pagename,"c":number_of_results},...];
Then the autocomplete request will look like:
$("#autocomplete").autocomplete(data, {
matchContains: true,
formatItem: function(row, i, max) {
return row.n + " ("+row.c+")";
},
formatMatch: function(row, i, max) {
return row.n;
},
formatResult: function(row) {
return row.n;
}
});
$("#autocomplete").result(function(event, data, formatted) {
if(!data) {
alert("Please select an item");
} else {
window.location.href = data.p;
}
});
This will create an autocomplete that looks like item name (number of results)
and when clicked on an element, it will be redirected to the corresponding pagename element.
I have about 1000 items and the autocomplete speed is instant.
source to share
Server side PHP / SQL is slow.
Don't use PHP / SQL. My autocomplete is written in C ++ and uses hashtables for searching. See Performance here .
This computer is Celeron-300, FreeBSD, Apache / FastCGI.
And, you see, he quickly runs through huge dictionaries. 10,000,000 records is not a problem.
In addition, it supports priorities, dynamic translations and other features.
source to share