1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-11-05 22:36:16 +00:00
ympd/htdocs/sw.js

56 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-11-04 23:26:09 +00:00
var CACHE = 'myMPD-cache-v4.6.0';
var urlsToCache = [
'/',
'/player.html',
'/css/bootstrap.min.css',
2018-09-23 21:56:00 +00:00
'/css/mympd.min.css',
'/js/bootstrap-native-v4.min.js',
2018-09-23 21:56:00 +00:00
'/js/mympd.min.js',
'/js/player.min.js',
'/js/keymap.min.js',
'/assets/appicon-167.png',
'/assets/appicon-192.png',
'/assets/appicon-512.png',
'/assets/coverimage-httpstream.png',
'/assets/coverimage-notavailable.png',
'/assets/coverimage-loading.png',
'/assets/favicon.ico',
'/assets/MaterialIcons-Regular.ttf',
'/assets/MaterialIcons-Regular.woff',
'/assets/MaterialIcons-Regular.woff2'
];
self.addEventListener('install', function(event) {
2018-07-29 22:05:47 +00:00
event.waitUntil(
2018-07-29 22:20:22 +00:00
caches.open(CACHE).then(function(cache) {
2018-07-29 22:05:47 +00:00
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', function(event) {
if (event.request.url.match('^http://'))
return false;
event.respondWith(
caches.match(event.request).then(function(response) {
if (response)
return response
else
return fetch(event.request);
})
);
});
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.map(function(cacheName) {
2018-07-29 22:05:47 +00:00
if (cacheName != CACHE)
return caches.delete(cacheName);
})
);
})
);
});