Google & Dynamic Tools · Free guide

Adding fast search to a static website without a database (Pagefind vs. D1/JSON)

Because static sites have no running server database querying keywords per keystroke, adding a search bar requires either a build-time static search index (such as Pagefind or a compact JSON list) or an API Worker querying D1. For sites up to thousands of pages, Pagefind runs post-build on dist/ and delivers ultra-fast client-side search for $0/month.

By StaticLaunch · Four Media Group LLC

Why static HTML has no native backend search bar out of the box

A dynamic CMS queries MySQL tables whenever a visitor presses Enter. Prebuilt static hosting serves saved HTML directly, so search uses pre-indexed metadata chunks instead.

Option 1: Static post-build search with Pagefind (Zero server cost)

Running Pagefind right after astro build scans your rendered dist/ HTML, chunks tiny WebAssembly search indexes, and only downloads relevant fragments when a visitor actually types into the search box.

Example
npx astro build && npx pagefind --site dist

Option 2: Compact JSON or Cloudflare D1 FTS5 API

For small 20–100 item catalogs or MCP endpoint searches, filtering a compact build-time JSON index or querying SQLite FTS5 inside D1 keeps bundle sizes tiny cleanly.

Common questions

Will adding Pagefind slow down page loads for visitors who don't search?

No—when loaded lazily on input focus, initial landing pages remain completely unaffected.

When do you outgrow static Pagefind search?

Only on huge user-generated directories, private permissioned search results, or real-time pricing filters across 50,000+ inventory items—where D1 FTS5 or dedicated search backends fit better.

References

Provider interfaces and limits can change. Consult the original documentation before changing production settings.