2017-08-29 12:34:09 -07:00
|
|
|
/* global noConnection:false, Promise:false */
|
2017-10-13 06:16:12 -07:00
|
|
|
var CACHE_NAME = 'youcount-cache-1.3';
|
2017-08-27 15:57:35 -07:00
|
|
|
var urlsToCache = [
|
|
|
|
'/index.html',
|
|
|
|
'/images/social.png',
|
|
|
|
'/js/script.js'
|
|
|
|
];
|
2017-08-29 12:22:33 -07:00
|
|
|
self.addEventListener('install', function (event) {
|
|
|
|
event.waitUntil(
|
|
|
|
caches.open(CACHE_NAME)
|
|
|
|
.then(function (cache) {
|
|
|
|
return cache.addAll(urlsToCache);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2017-08-29 12:34:09 -07:00
|
|
|
self.addEventListener('activate', function (event) {
|
|
|
|
event.waitUntil(
|
|
|
|
caches.keys().then(function (cacheNames) {
|
|
|
|
return Promise.all(
|
|
|
|
cacheNames.filter(function (cacheName) {
|
2017-08-29 12:37:19 -07:00
|
|
|
return cacheName != CACHE_NAME;
|
2017-08-29 12:34:09 -07:00
|
|
|
}).map(function (cacheName) {
|
|
|
|
return caches.delete(cacheName);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
2017-08-27 15:57:35 -07:00
|
|
|
self.addEventListener('fetch', function (event) {
|
2017-08-28 13:56:46 -07:00
|
|
|
try {
|
|
|
|
event.respondWith(
|
|
|
|
caches.match(event.request)
|
|
|
|
.then(function (response) {
|
|
|
|
if (response) {
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
return fetch(event.request);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
} catch (err) {
|
|
|
|
noConnection('Service Worker failed to fetch!');
|
|
|
|
}
|
2017-08-27 15:57:35 -07:00
|
|
|
});
|