Bin
2025-12-17 611bfe34c3c96199eaaf6cf9e41a75892e44e879
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function registerServiceWorker(serviceWorkerFileName) {
  if ("serviceWorker" in navigator) {
    navigator.serviceWorker
      .register(serviceWorkerFileName)
      .then((registration) => {
        console.log("Service Worker registered with scope:", registration.scope);
      })
      .catch((error) => {
        console.log("Service Worker registration failed:", error);
      });
  }
}
 
function awakenServiceWorker() {
  if ("serviceWorker" in navigator) {
    navigator.serviceWorker.ready.then((registration) => {
      registration.active.postMessage({ type: "awaken" });
    });
  }
}
 
// sw.js and sw-fallback.js are part of the label-studio/label_studio/core/static/js/ directory
// and are copied with the rest of the static files when running `python manage.py collectstatic`
registerServiceWorker("/sw.js");
 
// Wake up the service worker when the page becomes visible
// This is needed to ensure we are cleaning up cache when the user is using the application
// and not only when the user is closing the tab.
document.addEventListener("visibilitychange", () => {
  if (!document.hidden) {
    awakenServiceWorker();
  }
});