-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add custom service worker to cache github requests
- Loading branch information
bkleiner
committed
Jun 26, 2023
1 parent
42c05d7
commit 706b8b0
Showing
7 changed files
with
2,858 additions
and
2,050 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.DS_Store | ||
node_modules | ||
/web/dist | ||
/dev-dist | ||
|
||
# local env files | ||
.envrc | ||
|
Large diffs are not rendered by default.
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,28 @@ | ||
import { clientsClaim } from "workbox-core"; | ||
import { registerRoute } from "workbox-routing"; | ||
import { StaleWhileRevalidate } from "workbox-strategies"; | ||
import { cleanupOutdatedCaches, precacheAndRoute } from "workbox-precaching"; | ||
|
||
declare let self: ServiceWorkerGlobalScope; | ||
|
||
const cacheUrls = [ | ||
"raw.githubusercontent.com", | ||
"api.github.com", | ||
"cors.bubblesort.me", | ||
]; | ||
|
||
self.__WB_DISABLE_DEV_LOGS = true; | ||
self.addEventListener("message", (event) => { | ||
if (event.data && event.data.type === "SKIP_WAITING") { | ||
self.skipWaiting(); | ||
} | ||
}); | ||
|
||
clientsClaim(); | ||
cleanupOutdatedCaches(); | ||
|
||
registerRoute( | ||
({ url }) => cacheUrls.includes(url.hostname), | ||
new StaleWhileRevalidate() | ||
); | ||
precacheAndRoute(self.__WB_MANIFEST); |
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
{ | ||
"extends": "@vue/tsconfig/tsconfig.node.json", | ||
"include": ["vite.config.*"], | ||
"extends": "@vue/tsconfig/tsconfig.json", | ||
"include": [ | ||
"vite.config.*" | ||
], | ||
"compilerOptions": { | ||
"composite": true, | ||
"types": ["node"] | ||
"types": [ | ||
"node" | ||
] | ||
} | ||
} | ||
} |
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