[web] [fix] Cache resource data only if the fetching succeed (#103816)
This commit is contained in:
@@ -134,9 +134,11 @@ self.addEventListener("fetch", (event) => {
|
||||
.then((cache) => {
|
||||
return cache.match(event.request).then((response) => {
|
||||
// Either respond with the cached resource, or perform a fetch and
|
||||
// lazily populate the cache.
|
||||
// lazily populate the cache only if the resource was successfully fetched.
|
||||
return response || fetch(event.request).then((response) => {
|
||||
cache.put(event.request, response.clone());
|
||||
if (response && Boolean(response.ok)) {
|
||||
cache.put(event.request, response.clone());
|
||||
}
|
||||
return response;
|
||||
});
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user