Skip to content
Permalink
2c2ca18846
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
48 lines (45 sloc) 1.38 KB
// Name of our cache
const cacheName = 'offline-pwa-gallery-v1';
// URLs to cache for offline mode
const urlsToCache = [
'https://cdn.skypack.dev/@ionic/core@next/css/core.css',
'https://cdn.skypack.dev/@ionic/core@next/css/ionic.bundle.css',
'https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.esm.js',
'https://cdn.jsdelivr.net/npm/@ionic/core/dist/ionic/ionic.js',
'css/styles.css',
'index.html',
'sw.js',
'./',
'images/antelope.jpg',
'images/bear.jpg',
'images/bison.jpg',
'images/bobcat.jpg',
'images/caracal.jpg',
'images/caribou-bulls.jpg',
'images/caribou.jpg',
'images/cheetah.jpg',
'images/coyote.jpg',
'images/ferrets.jpg',
'images/ox.jpg',
'images/tiger.jpg'
];
// Cache files on service worker registration
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(cacheName).then((cache) => {
return cache.addAll(urlsToCache);
})
);
});
// Intercept fetch requests to serve cached assets
self.addEventListener('fetch', (event) => {
if(event.request.url.match(/^https:\/\//)){
console.log('Browser is requesting:', event.request.url);
}
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
// It can update the cache to serve updated content on the next request
return cachedResponse || fetch(event.request);
})
);
});