Hello folks
I suspect a problem in this page : https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
I understand I can edit it directly, but for my first contribution I’d prefer to discuss it first!
The snippet containing
return resp || fetch(event.request).then(function(response) {
caches.open('v1').then(function(cache) {
cache.put(event.request, response.clone());
});
return response;
});
yields this error (at least in Chrome) :
Uncaught (in promise) TypeError: Failed to execute ‘clone’ on ‘Response’: Response body is already used
I think a fine fix is found in the source of the linked demo https://mdn.github.io/sw-test/sw.js :
return resp || fetch(event.request).then(function(response) {
let responseClone = response.clone();
caches.open('v1').then(function(cache) {
cache.put(event.request, responseClone);
});
return response;
});
So, I suggest I update the page.
What do you think?