Searching the Jamstack

Avatar of Chris Coyier
Chris Coyier on

Here’s Raymon Camden on adding site search functionality to a site that is statically hosted. A classic trick! Just shoot ’em to Google and scope the results to your site:

<form action="" method="get">
  <input type="search" name="q" value="site: " autofocus size="50">
  <input type="submit" value="Search">

I’d probably use JavaScript to inject that site: stuff before sending them over just so the search field doesn’t have that weird prefilled stuff in there, which might be off-putting. We covered that here.

Raymond then gets into Google Custom Search Engines, which is their product to provide scoped search on your own site. It’s desirable because it’s Google’s search for your own site. Whatever you might think of Google, they have great search results. That’s the thing. Even if you aren’t a Jamstack site and can freely use your own server to query content on your site, chances are your search results aren’t as good as Google’s.

Say you reach for another search solution… Solr, Lunr, ElasticSearch, Algolia. They are all kinda nice in their own way. The trick is making sure they have enough data for them to return good results, beyond just the content. You’ll never have an entire internet’s worth of backlinks to leverage, but ideally, you can factor in analytics data at the very least.

Direct Link →