Fix service worker placement
This commit is contained in:
parent
717ddb3884
commit
adcf571be4
3 changed files with 4 additions and 7 deletions
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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);
|
||||
})
|
||||
|
|
|
@ -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) => {
|
Loading…
Reference in a new issue