Skip to content
SearchJet
Astro Integration

Instant Search for Astro — Islands, Static & Edge Ready

AI-Powered Search for Static and Edge Sites

Add AI-powered search to Astro sites. Works with island hydration, static builds, and edge deployment.

Island Compatible
Static Export
Edge Ready
No Credit Card Required
Zero-JS by Default
Free Forever Plan
The Problem

Static Sites Need Search Too

Astro\'s zero-JS philosophy makes search tricky. You need something that respects static performance while delivering instant results.

⚠
Common Astro Pain Point

Algolia = Overkill for Static

Algolia pricing and complexity are designed for large apps. For a static Astro site, it's expensive overhead you don't need.

⚠
Common Astro Pain Point

Lunr.js = Client-Side Only + Slow

Lunr.js downloads the entire index to the client. Large content sites see multi-second load times with no typo tolerance.

⚠
Common Astro Pain Point

Custom Indexing = Complex

Build-time indexing requires complex scripts, and there's no real-time updates when content changes in your CMS.

The Solution

SearchJet + Astro

Drop-in search that respects Astro\'s island architecture. Hydrate only what you need, keep the rest static.

Island Architecture

Only the search box ships JavaScript — a small script or a framework island. The rest of your page stays static with zero JavaScript.

Static Export Native

The search API allows direct browser calls (CORS), so a search-only key works on a fully static site. Zero server required. Works perfectly with astro build.

Edge Runtime

Deploys to Cloudflare Pages, Vercel Edge, and Netlify Edge. Sub-150ms search, called straight from the edge.

Content Collections

Index .md and .mdx files from Astro content collections with one POST /index/bulk request after each build.

Framework Agnostic

Search is one HTTP request, so it works anywhere JavaScript runs. Use it in Astro islands, vanilla scripts, endpoints, or any component.

Tiny Footprint

No SDK to download. The search script is a few lines of your own code, and it only loads on pages that include it.

Copy-Paste Integration

Two approaches — Astro island or content collection indexing

Search Page with a Tiny Script Island

src/pages/search.astro
---
// src/pages/search.astro — static HTML; the only JS is the small <script> below
import BaseLayout from '../layouts/BaseLayout.astro';
---

<BaseLayout title="Search">
  <h1>Search Our Content</h1>
  <input id="q" type="search" placeholder="Search articles..." />
  <div id="results"></div>
</BaseLayout>

<script>
  // Astro bundles this as a module script; no framework runtime is shipped.
  const API = 'https://app.searchjetengine.com/api/v1/search';
  const SEARCH_KEY = import.meta.env.PUBLIC_SEARCHJET_SEARCH_KEY; // search-only key

  const input = document.getElementById('q') as HTMLInputElement;
  const out = document.getElementById('results')!;
  let timer;

  input.addEventListener('input', () => {
    clearTimeout(timer);
    timer = setTimeout(async () => {
      const q = input.value.trim();
      if (!q) return out.replaceChildren();
      const res = await fetch(`${API}?q=${encodeURIComponent(q)}&limit=10`, {
        headers: { Authorization: `Bearer ${SEARCH_KEY}` },
      });
      const { results = [] } = await res.json(); // results is the array of hits
      out.replaceChildren(...results.map((hit) => {
        const article = document.createElement('article');
        const link = document.createElement('a');
        link.href = hit.url;
        link.textContent = hit.title;
        const excerpt = document.createElement('p');
        excerpt.textContent = hit.excerpt ?? '';
        article.append(link, excerpt);
        return article;
      }));
    }, 200); // debounce
  });
</script>

Content Collection Indexing Script

src/pages/search-docs.json.ts + scripts/index-content.mjs
// src/pages/search-docs.json.ts — astro build writes dist/search-docs.json
import { getCollection } from 'astro:content';

export async function GET() {
  const posts = await getCollection('blog');
  const documents = posts.map((post) => ({
    id: post.id,
    title: post.data.title,
    content: post.body ?? '',
    url: `https://example.com/blog/${post.id}/`,
    excerpt: post.data.description,
    type: 'post',
    date: post.data.date.toISOString(),
    metadata: { tags: post.data.tags ?? [] },
  }));
  return new Response(JSON.stringify({ documents }));
}

// scripts/index-content.mjs — run after build: node scripts/index-content.mjs
// Server-side only: the ADMIN key comes from an env var, never from browser code.
import { readFile } from 'node:fs/promises';

const { documents } = JSON.parse(
  await readFile('dist/search-docs.json', 'utf8')
);

const res = await fetch('https://app.searchjetengine.com/api/v1/index/bulk', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.SEARCHJET_PRIVATE_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ documents }),
});

const data = await res.json();
console.log(`Indexed ${documents.length} posts (task ${data.taskUid})`);

Need a complete starter project?

View GitHub Examples
Performance Gains

Measurable Performance Improvements

Illustrative comparison with a client-side Lunr.js index. Your results will vary.

MetricBeforeAfterImpact
Build Time ImpactIndex generated in every buildOne POST after deployNo search index in your build
Search Bundle Size45KB+ (Lunr)No SDK — a few lines of fetchNo search library to ship
Page Load TimeFull index downloadedNo index to downloadLighter search pages
SEO RankingsBaselineFaster, lighter pagesCan support better site metrics

Frequently Asked Questions

Everything you need to know about SearchJet for Astro

Does SearchJet work with Astro Islands?
Yes. Search runs from a tiny script or framework island that calls the REST API. Only the search UI ships JavaScript — the rest of the page stays static.
Can I use it with static output (SSG)?
Yes. The search API allows direct browser calls (CORS), so a static Astro build can query it with a search-only key. Zero server required. Keep your private key out of client code.
Does it work with Astro SSR?
Yes. In hybrid or SSR mode, add an endpoint such as src/pages/api/search.json.ts (with export const prerender = false) that calls GET /search with the key from an environment variable, or fetch in a page's frontmatter to pre-render results for SEO-critical pages.
Do I need to install anything for Astro?
No. SearchJet is a REST API: call GET /search from a script, island, endpoint, or frontmatter, and POST /index/bulk to index your content. No SDK needed — any HTTP client works.
How does it handle zero-JS by default?
Pages without a search box ship no JavaScript. On the search page, only the small search script runs — the rest of your Astro page remains completely static.
Does it work with Astro DB / Content Collections?
Yes, you can index any content collection or Astro DB data. Send it to POST /index/bulk with your private key from a build or deploy script, as shown above.

Still have questions?

Contact our support team

Ready to Add Search to Your Astro Site?

Join developers building exceptional search experiences with SearchJet

Free Forever Plan
No Credit Card
5-Min Setup

Already have an account? Log in

Related Use Cases