// Library
offline-queue
Holds API calls while a phone has no signal, then sends them in order once it does.
- license
- MIT
npm install offline-queue
README.md
MIT
offline-queue is a 2 kB TypeScript queue for apps people use in the field. Requests made with no signal are saved on the device, then sent in the order they were made once the connection comes back.
Usage
import { createQueue } from "offline-queue"
const queue = createQueue({
storage: "indexeddb",
retry: { times: 5, backoff: 2000 },
})
// Works the same with or without signal
await queue.add(() => api.post("/jobs/42/photos", form))What you get
- Jobs saved to IndexedDB or AsyncStorage, so they survive an app restart
- Sent in the order they were made, with retries and backoff
- queue.size and an onSent hook, so the screen can show what is still waiting
Why it exists
It started on QPIMS, where installers upload job photos from basements and rooftops. Uploads were failing without a word, and the office never saw the work. The queue fixed that in a week.
No dependencies. It runs the same in React Native and in the browser.
More from the lab.
06Everything in the lab- Experimentprompt-diffRuns two versions of a prompt on the same inputs and shows where the answers changed.
- Librarymoney-safeInteger-only money math for TypeScript, so a wallet never shows $0.30000000000000004.
- Toolsupa-seedFills a Supabase database with realistic test data, read straight from your own schema.