A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve service worker

+14 -28
+1
CHANGELOG.md
··· 3 3 ## Unreleased 4 4 5 5 - Fixes various issues with the album-cover view (eg. playback issues) 6 + - Service worker tweaks to improve performance and offline behaviour 6 7 7 8 8 9 ## 3.0.1
+9 -27
src/Javascript/Workers/service.js
··· 26 26 27 27 self.addEventListener("activate", event => { 28 28 event.waitUntil(self.clients.claim()) 29 + 30 + // Remove all caches except the one with the currently used `KEY` 31 + caches.keys().then(keys => { 32 + keys.forEach(k => { 33 + if (k !== KEY) caches.delete(k) 34 + }) 35 + }) 29 36 }) 30 37 31 38 32 39 self.addEventListener("install", event => { 33 40 const href = self.location.href.replace("service-worker.js", "") 34 - const promise = removeAllCaches() 35 - .then(_ => fetch("tree.json")) 41 + const promise = fetch("tree.json") 36 42 .then(response => response.json()) 37 43 .then(tree => { 38 44 const filteredTree = tree.filter(t => !exclude.find(u => u === t)) ··· 46 52 47 53 48 54 self.addEventListener("fetch", event => { 49 - // const isNotLocal = 50 - // !event.request.url.match(new RegExp("^https?\:\/\/127.0.0.1")) && 51 - // !event.request.url.match(new RegExp("^https?\:\/\/localhost")) 52 - 53 55 const isInternal = 54 56 !!event.request.url.match(new RegExp("^" + self.location.origin)) 55 57 ··· 84 86 "Bearer " + token 85 87 ) 86 88 87 - // Use cache if internal request & update cache in the background 89 + // Use cache if internal request 88 90 } else if (isInternal) { 89 91 let url = new URL(event.request.url) 90 92 url.search = "" ··· 95 97 .then(cache => cache.match(url)) 96 98 .then(match => match || fetch(url)) 97 99 ) 98 - 99 - if (!isOffline && event.request.mode !== "navigate") event.waitUntil( 100 - caches 101 - .open(KEY) 102 - .then(cache => fetch(url) 103 - .then(response => response.clone()) 104 - .then(response => cache.put(url, response)) 105 - ).catch(err => { 106 - console.error("Could not fetch " + url.href) 107 - console.error(err) 108 - }) 109 - ) 110 100 } 111 101 }) 112 102 ··· 128 118 129 119 event.respondWith(fetch(newRequest)) 130 120 } 131 - 132 - 133 - function removeAllCaches() { 134 - return caches.keys().then(keys => { 135 - const promises = keys.map(k => caches.delete(k)) 136 - return Promise.all(promises) 137 - }) 138 - }
+4 -1
src/Javascript/index.js
··· 56 56 let wire = {} 57 57 58 58 59 - function initialise() { 59 + function initialise(reg) { 60 60 app = Elm.UI.init({ 61 61 node: document.getElementById("elm"), 62 62 flags: { ··· 80 80 wire.clipboard() 81 81 wire.covers() 82 82 wire.webnative() 83 + 84 + // Check for service worker updates every hour 85 + setInterval(() => reg.update(), 1 * 1000 * 60 * 60) 83 86 } 84 87 85 88