-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔥 Removed npm package log: using pnpm
- Loading branch information
Showing
8 changed files
with
202 additions
and
5,163 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/// <reference types="@sveltejs/kit" /> | ||
import { build, files, version } from '$service-worker'; | ||
|
||
const CACHE = `cache-${version}`; | ||
|
||
const ASSETS = [ | ||
...build, | ||
...files | ||
]; | ||
|
||
self.addEventListener('install', (event) => { | ||
async function addFilesToCache() { | ||
const cache = await caches.open(CACHE); | ||
await cache.addAll(ASSETS); | ||
} | ||
|
||
event.waitUntil(addFilesToCache()); | ||
}); | ||
|
||
self.addEventListener('activate', (event) => { | ||
async function deleteOldCaches() { | ||
for (const key of await caches.keys()) { | ||
if (key !== CACHE) await caches.delete(key); | ||
} | ||
} | ||
|
||
event.waitUntil(deleteOldCaches()); | ||
}); | ||
|
||
self.addEventListener('fetch', (event) => { | ||
async function respond() { | ||
const url = new URL(event.request.url); | ||
const cache = await caches.open(CACHE); | ||
|
||
if (ASSETS.includes(url.pathname)) { | ||
return cache.match(url.pathname); | ||
} | ||
|
||
try { | ||
const response = await fetch(event.request); | ||
|
||
if (response.status === 200) { | ||
cache.put(event.request, response.clone()); | ||
} | ||
|
||
return response; | ||
} catch { | ||
return cache.match(event.request); | ||
} | ||
} | ||
|
||
event.respondWith(respond()); | ||
}); |
Oops, something went wrong.