Static Site Search with Gatsby and Algolia
6 minutes to read — 1166 words
About a month ago, I wrote about developing a static website with server-side Javascript. As I discovered, there are a lot of advantages to a static site. But one of the disadvantages to the lack of a database is that it isn’t obvious how to make the site searchable. With no database to pull from, generating search results can be a challenge.
Rather than pull search results from a database and generating results pages with server-side scripts, static sides tend to opt for storing results in a single file or external database and relying on AJAX to submit queries of the search index. That’s easier said than done, though. Every time you update the site, you need to rebuild the index (whether it’s a JSON file or a database hosted somewhere else). Then, when your users are actually searching the website, you need to set up the AJAX calls to the index and transform the response into a user interface.