`title: Fetch 断线重试与指数退避持久化队列``categories: Web 开发/前端/数据管理``keywords: Fetch,断线重试,指数退避,IndexedDB,队列``description: 将失败的网络请求入队到 IndexedDB 并使用指数退避进行重试,结合 SW 或页面调度保障可靠性。`入队与重试async function enqueue(db, req) {
return new Promise((resolve, reject) => {
const tx = db.transaction('queue', 'readwrite');
tx.objectStore('queue').put({ id: crypto.randomUUID(), req, attempt: 0, ts: Date.now() });
tx.oncomplete = () => resolve();
tx.onerror = () => reject(tx.error);
});
}

发表评论 取消回复