Skip to content

Commit

Permalink
Add some delay before updating the DOM with search results.
Browse files Browse the repository at this point in the history
This change improves the performance in Chromium when the <input> has only one
or two letters.
  • Loading branch information
ayosec committed Nov 7, 2024
1 parent 782d79a commit a0e9731
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/ffdocs/view/javascript/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ class SearchInput {
this.prefetchLinks = new Set();

elem.addEventListener("input", () => {
this.update(elem.value.trim().toLowerCase());
const query = elem.value.trim().toLowerCase();
const delay = query.length < 3 ? 300 : 50;

if (this.timerAfterInput !== undefined) {
clearTimeout(this.timerAfterInput);
}

this.timerAfterInput = setTimeout(() => this.update(query), delay);
});

elem.addEventListener("keydown", (event) => {
Expand Down

0 comments on commit a0e9731

Please sign in to comment.