Files
myprojplanet_vite/src-pwa/register-service-worker.js
2025-03-23 22:53:53 +01:00

51 lines
1.7 KiB
JavaScript
Executable File

/*
* This file is picked up by the build system only
* when building for PRODUCTION
*/
import { register } from 'register-service-worker'
const SW_FILE = `/${import.meta.env.VITE_SERVICE_WORKER_FILE}`;
console.log('SWFILE: ', SW_FILE);
register(SW_FILE, {
scope: '/',
/************* ✨ Codeium Command ⭐ *************/
/**
* When the app has finished populating the caches and the service worker has taken control of the page,
* this callback will be triggered. It's a good place to do something with the registration such as post a message
* to the waiting service worker, or add an event listener for future push events.
*/
/****** 37dbd402-a66f-4a9b-9ead-63e4617559c1 *******/
ready() {
console.log('READY::: App is being served from cache by a service worker ' + import.meta.env.VITE_SERVICE_WORKER_FILE)
},
registered(registration) { // registration -> a ServiceWorkerRegistration instance
console.log('REGISTERED::: !!!', import.meta.env.VITE_SERVICE_WORKER_FILE)
},
cached(registration) {
console.log('CACHED::: Content has been cached for offline use.')
},
updatefound(registration) {
console.log('UPDATEFOUND::: New content is downloading.')
// $('#newvers').addClass('btnNewVersShow').removeClass("btnNewVersHide")
},
updated(registration) {
document.dispatchEvent(
new CustomEvent('swUpdated', { detail: registration })
)
console.log('New content is available; please refresh.')
},
offline() {
console.log('No internet connection found. App is running in offline mode.')
},
error(err) {
console.error('Error during service worker registration:' + err)
},
});
// ServiceWorkerRegistration: https://developer.mozilla.org/enUs/docs/Web/API/ServiceWorkerRegistration