Search is the one feature static sites are supposed to give up. Pagefind removes that excuse, so I wired it into this site and measured what it cost.

What I Did

Pagefind runs after the build, against the generated HTML. It reads the DOM, extracts content from elements marked with data-pagefind-body, and writes a static index plus a small JavaScript bundle into the output directory.

Setup

  1. Build the site as usual.
  2. Run the indexer against the output directory.
  3. Copy the index into the published output.
  4. Load the index only when the user opens search.

The last step matters. The bundle is small, but there is no reason to ship it on first paint.

What Worked

  • No service, no key, no quota. The index is files on the same CDN.
  • Relevance is respectable. Titles and headings are weighted properly out of the box.
  • Section and tag filtering works without extra configuration.

What Did Not

  • Indexing must happen after every build. Forgetting it silently produces an empty search.
  • Excerpts include template chrome unless the body is scoped carefully. Mark the content container, not the page.
  • The fallback question. If indexing fails, search returns nothing rather than failing loudly.
Note to self
Because an empty index looks like “no results”, I kept a JSON fallback index built by Hugo itself. If the static index is missing, the client falls back to the Hugo-built one.

Verdict

Good enough to ship, with one caveat: treat index generation as part of the build, not as an optional step. I now run it in the same command as the build so it cannot be forgotten.

Related reading