-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix service worker to enable it to replace old one (#389)
* fix: add cleanupOutdatedCaches option * use custom sw & force update * skipWaiting and claim before cleanupOutdatedCaches * add ts files to NetworkFirst cache * remove ts from cache * register sw on index.html * change sw from ts to js * test updates to trigger build * registerSW in index.html * remove unused code and comment of registering sw * update files to trigger build
- Loading branch information
1 parent
5d47e3c
commit 7c6cd35
Showing
7 changed files
with
80 additions
and
50 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
/* eslint-disable no-restricted-globals */ | ||
import { clientsClaim, setCacheNameDetails } from "workbox-core"; | ||
import { precacheAndRoute, cleanupOutdatedCaches } from "workbox-precaching"; | ||
import { registerRoute } from "workbox-routing"; | ||
import { NetworkFirst, StaleWhileRevalidate } from "workbox-strategies"; | ||
|
||
self.__WB_DISABLE_DEV_LOGS = true; | ||
|
||
self.skipWaiting(); | ||
clientsClaim(); | ||
|
||
cleanupOutdatedCaches(); | ||
precacheAndRoute(self.__WB_MANIFEST); | ||
|
||
setCacheNameDetails({ | ||
prefix: "wasedatime-cache", | ||
precache: "precache", | ||
runtime: "runtime", | ||
}); | ||
|
||
registerRoute( | ||
({ event }) => event.request.mode === "navigate", | ||
new NetworkFirst({ | ||
fetchOptions: { | ||
credentials: "same-origin", | ||
}, | ||
}) | ||
); | ||
|
||
registerRoute( | ||
/.*\.(?:js|css)/, | ||
new NetworkFirst({ | ||
fetchOptions: { | ||
credentials: "same-origin", | ||
}, | ||
}) | ||
); | ||
|
||
registerRoute( | ||
/.*\.(?:png|jpg|jpeg|svg|gif|woff|woff2|eot|ttf|otf)/, | ||
new StaleWhileRevalidate({ | ||
fetchOptions: { | ||
credentials: "same-origin", | ||
}, | ||
}) | ||
); | ||
|
||
self.addEventListener("message", (event) => { | ||
if (event.data && event.data.type === "SKIP_WAITING") { | ||
self.skipWaiting(); | ||
clientsClaim(); | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"es2016.array.include", | ||
"es2018", | ||
"esnext", | ||
"WebWorker", | ||
], | ||
}, | ||
"include": ["src"], | ||
|
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