HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

jQuery autocomplete for all place names in the UK

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
theallplacenamesjqueryautocompletefor

Problem

I made an autocomplete input box of every town, city and village in the UK. Yes, every single one. The load times are painful so is there a way to reduce that?

Here is a sample:


$( function() {
    var availableTags = [
      "Abberton",
      "Abbeytown",
      "Abbots Bromley",
      "Abbots Leigh",
      "Abbotsbury",
      "Abbotskerswell",
      "Abbotsley"
    ];
$("#location").autocomplete({
      source: availableTags
});
});


Here is a JSFiddle with the entire list, which has 7726 items.

Solution

You can improve performance by using autocomplete function with this options:

$( "#location" ).autocomplete({
      source: availableTags,
      delay: 0,
      minLength: 2,
});


This library has a 300 ms delay by default. So setting delay to 0 disables it.
minLength is for loading the matches after the users typed at least 2 chars, I don't think there is a point to load them when you have only 1 character.

Good luck

Code Snippets

$( "#location" ).autocomplete({
      source: availableTags,
      delay: 0,
      minLength: 2,
});

Context

StackExchange Code Review Q#148568, answer score: 3

Revisions (0)

No revisions yet.