Head over to the search page to try out the newly added search feature!

Hugo has a docs page on search options. Most solutions leverage lunr or fuse, both JavaScript client-side libraries. This theme, Papermod, supports search with fuse.js via Hugo’s native JSON output format.

When enabled JSON output, I noticed file index.json had the full-text content of all blog posts. Fuse.js pulls this JSON client side and performs a fuzzy search on the content. Right now, the file size is 100KB, not bad. It did make me think about how long it will take to grow large enough that I’d rather not have taking up bandwidth. The search page is probably more likely to be used from a laptop where data transfer matters less than on a mobile device.

Pagefind is a static site client-side search library focused on bandwidth efficiency. It released 1.0.0 last week. When I ran the CLI on my site, it generated a binary index for more compression. Playing with it on the Pagefind website leads me to believe it stores compressed full text of the pages instead of just wordlists since it will show sentence fragments the search term was found in. Very interesting!

As we all have heard, “premature optimization is the root of all evil.” The theme’s default search on the full JSON dump of all blog posts is a fine place to start. Later if I write enough that it grows to 1MB, I will probably start looking at alternatives. I could investigate the level of compression something like Pagefind gives. It might scale closer to O(log n) and give more of a size difference than it does on my current small site size. Another option would be a search service like Algolia.