From e757c0ab105451553a355c36ef63d95d7dda8ca8 Mon Sep 17 00:00:00 2001 From: Sanyam Jain Date: Mon, 5 Feb 2024 17:49:54 +0530 Subject: [PATCH] add sw --- index.html | 16 ++++++++++++++++ sw.js | 19 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 sw.js diff --git a/index.html b/index.html index 158cb92..f79fd20 100644 --- a/index.html +++ b/index.html @@ -26,5 +26,21 @@

when to use

  • less user interactivity
  • + + diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..33bc555 --- /dev/null +++ b/sw.js @@ -0,0 +1,19 @@ +const CACHE_NAME = 'my-cache-v0'; +const urlsToCache = [ + '/', + '/index.html' +]; + +self.addEventListener('install', event => { + event.waitUntil( + caches.open(CACHE_NAME) + .then(cache => cache.addAll(urlsToCache)) + ); +}); + +self.addEventListener('fetch', event => { + event.respondWith( + caches.match(event.request) + .then(response => response || fetch(event.request)) + ); +});