Skip to content

Instantly share code, notes, and snippets.

@marcusandre
Last active November 19, 2018 09:12
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 marcusandre/afb23d6cf73d7c3a8ac9882037d78f10 to your computer and use it in GitHub Desktop.
Save marcusandre/afb23d6cf73d7c3a8ac9882037d78f10 to your computer and use it in GitHub Desktop.
Simple Service Worker to respond with cached request
(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