當我在Chrome中刷新(或脫機)時,我得到「This site can'無法達到「並將以下內容記錄到控制檯:The FetchEvent for "http://localhost:8111/survey/174/deployment/193/answer/offline/attendee/240/" resulted in a network error response: a redirected response was used for a request whose redirect mode is not "follow".
。當我在Firefox中刷新一切正常。有人可以解釋爲什麼發生這種情況?僅在Chrome(服務工作者)中:'...重定向響應用於重定向模式不是「跟隨」的請求
這是我簡化的SW。
importScripts("/static/js/libs/idb.js")
var CACHE_NAME = "upshot-cache-version3"
var urlsToCache = [...]
self.addEventListener("install", event => {
event.waitUntil(
caches
.open(CACHE_NAME)
.then(cache => {
urlsToCache.map(url => cache.add(url))
})
)
})
self.addEventListener("activate", event => {
clients.claim()
})
self.addEventListener('fetch', event => {
event.respondWith(
caches
.match(event.request)
.then(response => {
if (response) {
return response
}
var fetchRequest = event.request.clone()
return fetch(fetchRequest).then(response => {
if (!response || response.status !== 200 || response.type !== 'basic') {
return response
}
var responseToCache = response.clone()
caches.open(CACHE_NAME).then(cache => cache.put(event.request, responseToCache))
return response
})
})
)
})
感謝您的詳細回覆,Firefox版本實際上是55.0b13(Developer Edition)。 –
嗯......不知道爲什麼你會看到不同的行爲,在這種情況下。 https://bugzilla.mozilla.org/show_bug.cgi?id=1243792是Firefox實施跟蹤錯誤,並且已完成工作。 –