Local-First & Offline-Capable AI Web Apps: Service Workers, IndexedDB, SQLite WASM & ONNX
Why should a note-taking app, semantic search engine, or field-service PWA stop working the moment a user enters an airplane or subway tunnel? By combining Service Workers (Serwist), IndexedDB / OPFS, SQLite compiled to WebAssembly, and ONNX Runtime Web inside dedicated Web Workers, a Senior Freelance Full Stack & AI Programmer can build web applications that run 100% offline with zero server latency.
1. Architecture of a Local-First AI PWA (Journal: Private Markdown Notes)
- Client-Side AES-GCM Encryption: User notes and local API keys are encrypted in the browser using Web Crypto API (
PBKDF2key derivation +AES-GCM-256). - In-Browser Neural Embeddings: Quantized Transformer models run inside a background Web Worker via ONNX Runtime Web (`wasm` / `webgpu`), turning Markdown paragraphs into 384-dimensional float vectors without sending private text to any third-party cloud.
- SQLite WASM Vector Index: Vectors are persisted locally and queried in under 10 milliseconds for offline Retrieval-Augmented Generation (RAG).