On my backend, I have a JSON file containing suggested words for autocomplete in the search field.
To improve performance, I don't want the JSON to load every time the page loads; instead, I only want it to load when someone wants to use the search feature.
For autocomplete functionality, I am utilizing bootstrat3-typeahead (https://github.com/bassjobsen/Bootstrap-3-Typeahead)
Below is the script responsible for loading the JSON:
var searchSuggest = "http://localhost/searchSuggest.json";
$.get(searchSuggest, function(data){
$("#input-search").typeahead({
source: data,
autoSelect: false,
afterSelect: function(){
// local function that executes the search
search($("#input-search"))
}
});
});
I was considering loading the JSON on the input change event, but how can I ensure it loads only once?