Skip to content

Commit

Permalink
registered worker with scope param
Browse files Browse the repository at this point in the history
  • Loading branch information
sergesoroka committed Oct 5, 2024
1 parent 93ac2c9 commit ff091e1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions public/worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
let accessToken = null;

self.addEventListener("install", (event) => {
event.waitUntil(
caches.open("static-v1").then((cache) => {
return cache.addAll(["/", "/index.html"]);
})
);
self.skipWaiting();
});

self.addEventListener("activate", (event) => {
event.waitUntil(clients.claim());
console.log("Service worker activated");
Expand Down
4 changes: 3 additions & 1 deletion src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ const token = keycloak.token ? keycloak.token : stored_token;

const base_url = import.meta.env.PROD ? "/search/worker.js" : "/worker.js";

console.log("base url", base_url);

if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker
.register(base_url)
.register(base_url, { scope: "/search" })
.then((registration) => {
console.log(
"Service Worker registered with scope: ",
Expand Down

0 comments on commit ff091e1

Please sign in to comment.