Some changes...
This commit is contained in:
parent
bf95529bd9
commit
63247ddc22
32
src/index.ts
32
src/index.ts
|
@ -7,11 +7,27 @@ console.log("%cWARNING!!!" +
|
|||
"color: red; font-size: 30px;",
|
||||
"color: black; font-size: 15px;");
|
||||
|
||||
// Service worker registration
|
||||
if("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker.register("sw.js").then(registration => {
|
||||
console.log("Service worker registration successful with scope: ", registration.scope);
|
||||
}).catch(err => {
|
||||
console.log("Service worker registration failed: ", err);
|
||||
});
|
||||
}
|
||||
// Service worker registration for offline support
|
||||
const registerServiceWorker = async () => {
|
||||
if ('serviceWorker' in navigator) {
|
||||
try {
|
||||
const registration = await navigator.serviceWorker.register(
|
||||
'sw.js',
|
||||
{
|
||||
scope: '/',
|
||||
}
|
||||
);
|
||||
if (registration.installing) {
|
||||
console.log('Service worker installing');
|
||||
} else if (registration.waiting) {
|
||||
console.log('Service worker installed');
|
||||
} else if (registration.active) {
|
||||
console.log('Service worker active');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Registration failed with ${error}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
registerServiceWorker();
|
17
src/sw.js
17
src/sw.js
|
@ -2,7 +2,18 @@ importScripts(
|
|||
'https://storage.googleapis.com/workbox-cdn/releases/6.4.1/workbox-sw.js'
|
||||
);
|
||||
|
||||
workbox.routing.registerRoute(
|
||||
({ request }) => request.destination === 'image',
|
||||
new workbox.strategies.CacheFirst()
|
||||
const navigationRoute = new workbox.routing.NavigationRoute(
|
||||
new workbox.strategies.NetworkFirst({
|
||||
cacheName: 'apexie-navigations'
|
||||
})
|
||||
);
|
||||
|
||||
const imageAssetRoute = new workbox.routing.Route(({request}) => {
|
||||
return request.destination === 'image';
|
||||
}, new workbox.strategies.CacheFirst({
|
||||
cacheName: 'apexie-image-assets'
|
||||
})
|
||||
);
|
||||
|
||||
workbox.routing.registerRoute(navigationRoute);
|
||||
workbox.routing.registerRoute(imageAssetRoute);
|
Loading…
Reference in New Issue