我正在嘗試使用緩存優先策略實現 PWA,該策略還嘗試通過在 waitUntil() 中獲取來更新緩存資產。如果有多個請求在(幾乎)同時開始,這會阻塞并使副線程并發嗎?這是我的代碼: self.addEventListener("fetch", (oEvent) => { oEvent.respondWith(caches.match(oEvent.request).then((oRes) => { if (oRes) { oEvent.waitUntil(fetch(oEvent.request) .then((oFetchRes) => { return caches.open(DYNAMIC_CACHE).then((oCache) => { oCache.put(oEvent.request.url, oFetchRes); }); })) return oRes } else { return fetch(oEvent.request) .then((oFetchRes) => { return caches.open(DYNAMIC_CACHE).then((oCache) => { oCache.put(oEvent.request.url, oFetchRes.clone()); return oFetchRes; }); }) .catch(() => { return new Response(JSON.stringify({}), { status: 503, statusText: "app_offline_and_missing_resource", }); }) }}) );});歡迎任何幫助,我仍然是 PWA 新手。
Service Worker 可以在獲取處理程序中使用 waitUntil 處理并發請求嗎?
慕田峪7331174
2023-03-24 14:41:21