---
title: "How MDN’s autocomplete search works"
description: "MDN Web Docs' autocomplete search runs entirely in the browser."
url: "https://swe.quest/articles/how-mdn-s-autocomplete-search-works-2a24a3a272638b76"
canonical: "https://hacks.mozilla.org/2021/08/mdns-autocomplete-search/"
source: "Mozilla Hacks"
published: "2021-08-03"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 5
tags: ["search","frontend","web-performance","javascript","react"]
---

# How MDN’s autocomplete search works

A post on [Mozilla Hacks](https://swe.quest/sources/mozilla-hacks.md), published 2021-08-03, 5 min read, Deep dive. Original: [https://hacks.mozilla.org/2021/08/mdns-autocomplete-search/](https://hacks.mozilla.org/2021/08/mdns-autocomplete-search/)

## Summary

MDN Web Docs' autocomplete search runs entirely in the browser. It lazy-loads a Brotli-compressed JSON index of every document title per locale (11,690 en-US titles, 144KB over the wire) only when the user focuses or hovers the search box or presses \`/\`. FlexSearch builds an in-memory index that is reused across keystrokes, and downshift handles the accessible React dropdown. Ranking comes from pre-sorting the index by relative pageview popularity at build time, so FlexSearch's matches keep that natural order. Typing \`/\` first switches to VS Code-style fuzzy matching on URL paths, which also works offline for content authors on a local preview server.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Search](https://swe.quest/tags/search.md) (Backend & APIs)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [Web performance](https://swe.quest/tags/web-performance.md) (Web & mobile)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)
- [React](https://swe.quest/tags/react.md) (Web & mobile)

## Prerequisites

- JavaScript DOM events ([easy posts on JavaScript](https://swe.quest/tags/javascript.md?difficulty=easy))
- React basics ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))

## Keywords

MDN Web Docs, FlexSearch, downshift, Yari, Brotli, Elasticsearch

## Related posts

- [How MDN’s site-search works](https://swe.quest/articles/how-mdn-s-site-search-works-3d88867dabcc5021.md): Mozilla Hacks · 2021-03-22 · Medium · 6 min read · Search, System design, Python
  MDN's site search builds every page nightly in a GitHub Action, emitting index.json files.
- [How GitHub Docs’ new search works](https://swe.quest/articles/how-github-docs-new-search-works-0f03307c816bdb86.md): GitHub Engineering · 2023-03-09 · Medium · 10 min read · Search, JavaScript
  GitHub Docs replaced its in-memory Node.js site search, which loaded serialized indexes from the Git repo for eight languages and five versions, with Elasticsearch.
- [A brief history of code search at GitHub](https://swe.quest/articles/a-brief-history-of-code-search-at-github-ac152c8901d98c95.md): GitHub Engineering · 2021-12-15 · Medium · 13 min read · Search, Scaling, Developer tools
  GitHub's code search evolved from a public-only Solr index plus \`git grep\` for private repos, to a decade-long Elasticsearch deployment that grew to 162 nodes, 1.25PB of storage and over 53 billion indexed files.
- [Search From a Million Books in Milliseconds With Neon and pg\_search](https://swe.quest/articles/search-from-a-million-books-in-milliseconds-with-neon-and-pg-search-2b2bd7a3bf8b0ad8.md): Neon · 2025-03-26 · Medium · 6 min read · PostgreSQL, Search, Performance engineering
  Swapping the OpenAI-embedding semantic search in Vercel's Next.js Book Inventory template for pg\_search's BM25 full-text index on Neon Postgres made title searches over a million Goodreads books roughly 180–236x faster, dropping from about 2.7 seconds to 11–14 ms. The setup loads the dataset into a books table, prewarms the table and index with pg\_prewarm, creates a covering bm25 index, and queries with the @@@ operator and paradedb.match in conjunction\_mode.
- [Creating an accessible search experience with the QueryBuilder component](https://swe.quest/articles/creating-an-accessible-search-experience-with-the-querybuilder-component-ffcb7d20ca7f5c3b.md): GitHub Engineering · 2022-12-13 · Medium · 9 min read · Accessibility, Frontend, Design systems, Search
  GitHub's QueryBuilder is a combobox-based search input built to stay accessible while supporting per-character styling, suggestions with different actions, and grouped results.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
