Last active
November 19, 2018 09:12
-
-
Save marcusandre/afb23d6cf73d7c3a8ac9882037d78f10 to your computer and use it in GitHub Desktop.
Simple Service Worker to respond with cached request
This file contains hidden or 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
(function () { | |
'use strict' | |
self.addEventListener('fetch', event => { | |
let request = event.request | |
if (request.method !== 'GET') { | |
return | |
} | |
event.respondWith( | |
caches.match(request) | |
.then(response => { | |
return response || fetch(request) | |
}) | |
) | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment