Back to notes

Search That Belongs on a Static Site

Pagefind adds local search to a static Astro site without a service account, network dependency, or turning the whole site into an application.

Search on a small site usually comes with strings attached: a hosted service, an API key, a script on every page, or a quiet nudge toward turning the whole thing into an app. I wanted search that felt like part of the site instead of a guest.

Pagefind fits that job. It indexes the built HTML and ships a compact static search bundle alongside it. No account, no server, and no search runtime loaded on pages that are only for reading.

Build Time Is the Right Time

Pagefind runs after Astro finishes the build, so the index is made from the finished pages readers see, including MDX output and project pages. There is no second copy of the content to keep in sync.

The layout marks indexable content explicitly. Pages set to noindex stay out, and hidden metadata, such as microformats, is excluded so it cannot leak into result excerpts. The build fails if a noindex page is marked for indexing.

Deployment stays boring in the best way. The dist directory includes the Pagefind assets, so the search index ships with the pages it describes.

A Better Boundary

Only the search page loads the search interface, and the Pagefind runtime waits for the first real query. Every other page stays focused on reading, scanning, and navigation.

The query lives in the URL as ?q=, so a search can be bookmarked, shared, or reloaded. On pages with a search field, / focuses it. Elsewhere, Cmd/Ctrl K jumps to the search page.

That boundary later made new features easier. The same static index now powers a WebMCP search tool for agents, without adding a search service.

For this archive, the useful split is simple: build the index with the content, and load the search runtime when someone asks a question. Reading a note should not pay for a search that never happens.

The live search uses the index built with these pages, with shareable queries and no service account.

Search the site for Astro

By Dondi BoguskyUpdated