Skip to content

Commit a0e9731

Browse files
committed
Add some delay before updating the DOM with search results.
This change improves the performance in Chromium when the <input> has only one or two letters.
1 parent 782d79a commit a0e9731

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/ffdocs/view/javascript/search.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ class SearchInput {
44
this.prefetchLinks = new Set();
55

66
elem.addEventListener("input", () => {
7-
this.update(elem.value.trim().toLowerCase());
7+
const query = elem.value.trim().toLowerCase();
8+
const delay = query.length < 3 ? 300 : 50;
9+
10+
if (this.timerAfterInput !== undefined) {
11+
clearTimeout(this.timerAfterInput);
12+
}
13+
14+
this.timerAfterInput = setTimeout(() => this.update(query), delay);
815
});
916

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

0 commit comments

Comments
 (0)