Static Site Search for Astro
I added search to three AI directory sites last month.
I compared four main options before I chose Pagefind. Here is why I picked it.
The Contenders
• Pagefind: A Rust-based library. It runs during build time and serves everything as static files. • Algolia DocSearch: A hosted service. It is fast and polished but costs money for commercial sites. • Lunr.js: A client-side library. It works offline but makes your initial page load heavy. • FlexSearch: A faster alternative to Lunr, but it still requires shipping the whole index to the browser.
Why I chose Pagefind
Index Size My sites have 1,000 entries. A Lunr index would add 4MB to every page load. Pagefind uses shards. It loads small chunks as the user types. The initial load stays under 30KB.
Cost Algolia costs $49 per month for commercial sites. My total budget for all three sites is $25 per month. Pagefind is free.
Deployment Pagefind creates static files. Cloudflare Pages caches these at the edge automatically. You do not need to manage API keys or worry about rate limits.
The Trade-offs
Pagefind is not perfect. You should know these two gaps:
• No Query Logging: Pagefind runs in the browser. It does not tell you what users search for. Algolia does this automatically. You must build your own logging layer for Pagefind. • Basic Typo Tolerance: Pagefind uses basic stemming. It struggles with big typos. Algolia handles typos much better.
Comparison Summary
• Pagefind: Free, uses static files, scales well with lazy loading, basic typo tolerance. • Algolia: $49/mo, uses cloud infrastructure, scales well, strong typo tolerance. • Lunr.js: Free, ships index with page, poor scaling, weak typo tolerance.
My Verdict
If you run a static site on a small budget with 500 to 1,000 entries, use Pagefind. If you need advanced analytics and perfect typo tolerance, pay for Algolia.
