Skip to content

Instantly share code, notes, and snippets.

@LiorB-D
Created February 10, 2022 02:15
Show Gist options
  • Select an option

  • Save LiorB-D/b2a087895a3f12e729844dff065a3977 to your computer and use it in GitHub Desktop.

Select an option

Save LiorB-D/b2a087895a3f12e729844dff065a3977 to your computer and use it in GitHub Desktop.
var staticCacheName = "hello-pwa";
self.addEventListener("install", function (e) {
e.waitUntil(
caches.open(staticCacheName).then(function (cache) {
return cache.addAll(["/"]);
})
);
});
self.addEventListener("fetch", function (event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function (response) {
return response || fetch(event.request);
})
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment