Skip to content

Instantly share code, notes, and snippets.

@hinaloe
Last active June 19, 2018 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hinaloe/fa4fe161cc03e4ff52185d792dfdbcd5 to your computer and use it in GitHub Desktop.
Save hinaloe/fa4fe161cc03e4ff52185d792dfdbcd5 to your computer and use it in GitHub Desktop.
diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js
index 2435da117..b314ebae1 100644
--- a/app/javascript/mastodon/service_worker/entry.js
+++ b/app/javascript/mastodon/service_worker/entry.js
@@ -32,8 +32,11 @@ self.addEventListener('fetch', function(event) {
const asyncCache = openWebCache();
event.respondWith(asyncResponse.then(
- response => asyncCache.then(cache => cache.put('/', response.clone()))
- .then(() => response),
+ response => {
+ const clonedResponse = response.clone();
+ asyncCache.then(cache => cache.put('/', clonedResponse)).catch();
+ return response;
+ },
() => asyncCache.then(cache => cache.match('/'))));
} else if (url.pathname === '/auth/sign_out') {
const asyncResponse = fetch(event.request);
@@ -58,14 +61,9 @@ self.addEventListener('fetch', function(event) {
return asyncResponse.then(response => {
if (response.ok) {
- const put = cache.put(event.request.url, response.clone());
-
- put.catch(() => freeStorage());
-
- return put.then(() => {
- freeStorage();
- return response;
- });
+ cache
+ .put(event.request.url, response.clone())
+ .catch(err=>console.error(err)).then(freeStorage()).catch();
}
return response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment