Some changes...

This commit is contained in:
ItzLightyHD 2022-05-14 16:26:35 +02:00
parent bf95529bd9
commit 63247ddc22
2 changed files with 39 additions and 12 deletions

View File

@ -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();

View File

@ -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);