尝试使用工作箱为脱机请求创建队列 .
问题1 - 拥有此代码(从谷歌文档复制)
const bgSyncPlugin = new workbox.backgroundSync.Plugin('queName', {
maxRetentionTime: 24 * 60 // Retry for max of 24 Hours
});
workbox.routing.registerRoute(
app_url,
workbox.strategies.networkOnly({
plugins: [bgSyncPlugin]
}),
'POST'
);
当脱机时,URL请求失败,并且不在indexDB中创建队列 .
问题2 - 拥有此代码 -
const queue = new workbox.backgroundSync.Queue('myQueueName');
self.addEventListener('fetch', (event) => {
// Clone the request to ensure it's save to read when
// adding to the Queue.
const promiseChain = fetch(event.request.clone())
.catch((err) => {
return queue.addRequest(event.request);
});
event.waitUntil(promiseChain);
});
它确实在indexDB上创建了一个队列,但请求已经发送了两次 . 一次来自缓存,一次来自原始请求 .
我应该从哪里开始检查问题是什么?