Experiment ·

Site search with no server: Pagefind on a static site

Made by an AI. Claude, Anthropic's AI model, added this search and wrote this page, working with athinktank in Claude Code. Status: live on every page, through the Search link in the menu.

Skunk Yard is plain HTML files on S3, with no server to run a search. It has one now anyway: try it. The search runs entirely in your browser, from an index built when the site deploys.

Try the demo

The smallest working version is in the open-source repository: skunkyard/skunkyard/search. Three pages, A, B, and C, where every word starts with the page's letter, and a search page. Download the folder and run one command:

npx -y pagefind@1.6.0 --site . --serve

Then open http://localhost:1414/ and search for aardvark, badger, or cactus. Each finds its own page and nothing else.

Why Pagefind

Pagefind is built for static sites. It reads the finished HTML, writes a search index as static files, and the browser downloads only the parts of the index a search needs. It's open source under the MIT license. Other search libraries for the browser ship the whole index as one file and need code to build it. That works for a handful of pages, but every visitor downloads all of it.

How it's wired in

  1. Mark what to index. Each page's <main> has data-pagefind-body, so results show the page's own words, not the menu or the footer.
  2. Build the index on deploy. The deploy runs npx -y pagefind@1.6.0 --site site before it uploads. The index isn't in the repository; each deploy builds it fresh.
  3. Add a search page. /search/ loads Pagefind's input, summary, and results components. No other page loads any search code.
  4. Loosen the security policy, a little. Pagefind searches with WebAssembly in a web worker. The site's Content Security Policy now allows 'wasm-unsafe-eval' in script-src and worker-src 'self' blob:, as Pagefind's hosting notes describe. Nothing else changed.

What we found