`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); }); }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.529747s