35 lines
735 B
JavaScript
35 lines
735 B
JavaScript
var CACHE_NAME = 'snapdrop-cache-v1.03';
|
|
var urlsToCache = [
|
|
'/',
|
|
'/styles.css',
|
|
'/scripts/network.js',
|
|
'/scripts/ui.js',
|
|
'/sounds/blop.mp3',
|
|
'/images/favicon-96x96.png'
|
|
];
|
|
|
|
self.addEventListener('install', function(event) {
|
|
// Perform install steps
|
|
event.waitUntil(
|
|
caches.open(CACHE_NAME)
|
|
.then(function(cache) {
|
|
console.log('Opened cache');
|
|
return cache.addAll(urlsToCache);
|
|
})
|
|
);
|
|
});
|
|
|
|
|
|
self.addEventListener('fetch', function(event) {
|
|
event.respondWith(
|
|
caches.match(event.request)
|
|
.then(function(response) {
|
|
// Cache hit - return response
|
|
if (response) {
|
|
return response;
|
|
}
|
|
return fetch(event.request);
|
|
}
|
|
)
|
|
);
|
|
});
|