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

Configure Feed

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

Cache first strategy for service worker

+22 -10
+22 -10
src/Javascript/Workers/service.js
··· 36 36 .then(response => response.json()) 37 37 .then(tree => { 38 38 const filteredTree = tree.filter(t => !exclude.find(u => u === t)) 39 - const whatToCache = [ href, `${href}/about` ].concat(filteredTree) 39 + const whatToCache = [ href, `${href}about`, "/", "/about" ].concat(filteredTree) 40 40 return caches.open(KEY).then(c => Promise.all(whatToCache.map(x => c.add(x)))) 41 41 }) 42 42 .then(_ => self.skipWaiting()) ··· 56 56 const isOffline = 57 57 !self.navigator.onLine 58 58 59 - // Use cache if offline and identified as cached (internal) 60 - if (isInternal && isOffline) { 61 - const promise = caches 62 - .match(event.request) 63 - .then(r => r || fetch(event.request)) 64 - 65 - event.respondWith(promise) 66 - 67 59 // When doing a request with basic authentication in the url, put it in the headers instead 68 - } else if (event.request.url.includes("service_worker_authentication=")) { 60 + if (event.request.url.includes("service_worker_authentication=")) { 69 61 const url = new URL(event.request.url) 70 62 const token = url.searchParams.get("service_worker_authentication") 71 63 ··· 92 84 "Bearer " + token 93 85 ) 94 86 87 + // Use cache if internal request & update cache in the background 88 + } else if (isInternal) { 89 + let url = new URL(event.request.url) 90 + url.search = "" 91 + 92 + event.respondWith( 93 + caches 94 + .open(KEY) 95 + .then(cache => cache.match(url)) 96 + .then(match => match || Promise.reject("no-match")) 97 + ) 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 + ) 106 + ) 95 107 } 96 108 }) 97 109