{
name: "skoczylas",
short_name: "skoczylas",
icons: [
{
src: "img/fav/android-icon-36x36.png",
sizes: "36x36",
type: "image/png",
density: "0.75"
},
{
src: "img/fav/android-icon-48x48.png",
sizes: "48x48",
type: "image/png",
density: "1.0"
}
],
lang: "en",
start_url: "index.html",
display: "standalone",
orientation: "portrait",
theme_color: "#212121",
background_color: "#212121"
}
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js', {scope: './'})
.then((registration) => { ... })
.catch((error) => { ... });
});
}
self.addEventListener('install', (event) => { ... }); // InstallEvent
self.addEventListener('activate', (event) => { ... }); // ExtendableEvent
self.addEventListener('message', (event) => { ... }); // MessageEvent
self.addEventListener('fetch', (event) => { ... }); // FetchEvent
self.addEventListener('sync', (event) => { ... }); // SyncEvent
self.addEventListener('push', (event) => { ... }); // PushEvent
self.skipWaiting();
event.waitUntil(promise);
event.waitUntil(
self.caches.open(name)
.then(cache => cache.addAll([ ... ]))
);
event.respondWith(
self.caches.match(event.request)
.then((response) => {
if (response) {
return response; // cached response
}
const fetchRequest = event.request.clone();
return fetch(fetchRequest); // network reponse
})
);
event.respondWith(
self.caches.match(event.request)
.then((response) => {
if (response) {
return response; // cached response
}
const fetchRequest = event.request.clone();
return fetch(fetchRequest).then((response) => {
if(!response || response.status !== 200 || response.type !== 'basic') {
return response; // network reponse which should not be cached
}
const responseToCache = response.clone();
self.caches.open(name)
.then((cache) => cache.put(event.request, responseToCache)); // update cache
return response; // network reponse
});
})
);