Adding Blazing-Fast Client-Side Search with Fuse.js
Fuse.js is a powerful, lightweight fuzzy-search library that works entirely client-side. It's perfect for blogs and documentation sites where you want fast search without a backend.
Why Fuse.js?
- Lightweight: ~15KB gzipped.
- Fuzzy matching: Handles typos and approximate searches.
- Configurable: Weight fields, threshold tuning, and extended search.
- Zero dependencies: No server, no index builds.
Basic Setup
``ts
import Fuse from 'fuse.js'
const posts = [ { title: 'Brutalist Design', content: '...' }, { title: 'Nuxt 4 Migration', content: '...' }, ]
const fuse = new Fuse(posts, { keys: ['title', 'content', 'tags'], threshold: 0.3, includeScore: true, })
const results = fuse.search('brutalist')
// [{ item: {...}, score: 0.1, refIndex: 0 }]
`
Advanced Configuration
Tune the search experience with weighted keys:
`ts
const fuse = new Fuse(posts, {
keys: [
{ name: 'title', weight: 0.7 },
{ name: 'tags', weight: 0.5 },
{ name: 'content', weight: 0.3 },
],
threshold: 0.4,
distance: 100,
})
`
Title matches get priority, then tags, then body content. This creates a natural search ranking that matches user expectations.
Integration with Vue/Nuxt
Create a composable:
`ts
export function useSearch(posts: Ref``
The result is instant, typo-tolerant search that works offline and requires zero infrastructure.
Tags
More in Development
Migrating from Nuxt 3 to Nuxt 4: A Practical Guide
Step-by-step walkthrough of the Nuxt 4 migration process, covering the new directory structure, composables, and performance improvements.
State Management with Pinia in Nuxt 4
Setting up Pinia stores in Nuxt 4 with the manual plugin pattern β no module needed, just clean composition.