Skip to content

Commit

Permalink
feat: add page-copy service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
thraizz committed Jul 23, 2024
1 parent 6680bab commit 67d6d1f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
</head>
<body class="h-full">
<div id="root" />
<script>
if (typeof navigator.serviceWorker !== "undefined") {
navigator.serviceWorker.register("pwabuilder-sw.js");
}
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions public/pwabuilder-sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// This is the "Offline copy of pages" service worker

const CACHE = "pwabuilder-offline";

importScripts(
"https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js",
);

self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});

workbox.routing.registerRoute(
new RegExp("/*"),
new workbox.strategies.StaleWhileRevalidate({
cacheName: CACHE,
}),
);

0 comments on commit 67d6d1f

Please sign in to comment.