Last active
November 20, 2018 15:52
-
-
Save evuazeze/d1a496a4aafbf132487044a22b7f9467 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self.addEventListener('fetch', function(event) { | |
var request = event.request; | |
if (request.method === "POST") { | |
event.respondWith( | |
// Try to POST form data to server | |
fetch(event.request) | |
.catch(function() { | |
// If it doesn't work, post a message to reassure user | |
self.clients.matchAll().then(function (clients){ | |
clients.forEach(function(client){ | |
client.postMessage({ | |
msg: "Post unsuccessful! Server will be updated when connection is re-established.", | |
url: event.request.url | |
}); | |
}); | |
}); | |
}) | |
)} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment