From adcf571be40a8d3b29541b1920969988092fca84 Mon Sep 17 00:00:00 2001 From: William Brawner Date: Fri, 4 Feb 2022 21:16:26 -0700 Subject: [PATCH] Fix service worker placement --- client/package.json | 2 +- client/src/index.ts | 2 +- client/{src/sw.ts => sw.js} | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) rename client/{src/sw.ts => sw.js} (88%) diff --git a/client/package.json b/client/package.json index 4cacde2..e42078d 100644 --- a/client/package.json +++ b/client/package.json @@ -4,7 +4,7 @@ "description": "", "main": "index.js", "scripts": { - "prebuild": "copyfiles -Ve src/** index.html manifest.json **/*.css **/*.png ../dist/public", + "prebuild": "copyfiles -Ve src/** index.html manifest.json sw.js **/*.css **/*.png ../dist/public", "build": "tsc --project ./", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/client/src/index.ts b/client/src/index.ts index 6911ea6..6200c07 100644 --- a/client/src/index.ts +++ b/client/src/index.ts @@ -1,7 +1,7 @@ let socket: WebSocket | null = null; if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/static/js/sw.js', { 'scope': '/' }) + navigator.serviceWorker.register('/static/js/sw.js') .then(function (registration) { console.log('Registration successful, scope is:', registration.scope); }) diff --git a/client/src/sw.ts b/client/sw.js similarity index 88% rename from client/src/sw.ts rename to client/sw.js index 7326c7a..2067a41 100644 --- a/client/src/sw.ts +++ b/client/sw.js @@ -22,10 +22,7 @@ const filesToCache = [ const staticCacheName = 'pages-cache-v1'; -// TODO: Import this properly -type InstallEvent = any; - -self.addEventListener('install', (event: InstallEvent) => { +self.addEventListener('install', (event) => { console.log('Attempting to install service worker and cache static assets'); event.waitUntil( caches.open(staticCacheName) @@ -35,7 +32,7 @@ self.addEventListener('install', (event: InstallEvent) => { ); }); -self.addEventListener('fetch', (event: InstallEvent) => { +self.addEventListener('fetch', (event) => { event.respondWith( caches.match(event.request).then((response) => { caches.open(staticCacheName).then((cache) => {