Manifest and service work

{
“name”: “Docomo Wallet Explorer”,
“short_name”: “WalletExplorer”,
“start_url”: “index.html”,
“display”: “standalone”,
“background_color”: “#ffffff”,
“theme_color”: “#d0eaff”,
“orientation”: “portrait”,
“icons”: [
{
“src”: “icon-192.png”,
“sizes”: “192×192”,
“type”: “image/png”
},
{
“src”: “icon-512.png”,
“sizes”: “512×512”,
“type”: “image/png”
}
]
}

Service worker

const CACHE_NAME = ‘wallet-explorer-v1’;
const urlsToCache = [
‘index.html’,
‘manifest.json’,
‘icon-192.png’,
‘icon-512.png’
];

// Install: cache core files
self.addEventListener(‘install’, event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => cache.addAll(urlsToCache))
);
});

// Activate: clean up old caches
self.addEventListener(‘activate’, event => {
event.waitUntil(
caches.keys().then(keys => Promise.all(
keys.map(key => key !== CACHE_NAME && caches.delete(key)) ))
);
});

// Fetch: serve cached assets
self.addEventListener(‘fetch’, event => {
event.respondWith(
caches.match(event.request)
.then(response => response || fetch(event.request))
);
});

Leave a comment