run prettier
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
// the cache version gets updated every time there is a new deployment
|
||||
const CACHE_VERSION = 1;
|
||||
const CURRENT_CACHE = `lnbits-${CACHE_VERSION}-`;
|
||||
const CACHE_VERSION = 1
|
||||
const CURRENT_CACHE = `lnbits-${CACHE_VERSION}-`
|
||||
|
||||
const getApiKey = (request) => {
|
||||
return request.headers.get('X-Api-Key') || "none"
|
||||
const getApiKey = request => {
|
||||
return request.headers.get('X-Api-Key') || 'none'
|
||||
}
|
||||
|
||||
// on activation we clean up the previously registered service workers
|
||||
@@ -14,32 +14,38 @@ self.addEventListener('activate', evt =>
|
||||
cacheNames.map(cacheName => {
|
||||
const currentCacheVersion = cacheName.split('-').slice(-2, 2)
|
||||
if (currentCacheVersion !== CACHE_VERSION) {
|
||||
return caches.delete(cacheName);
|
||||
return caches.delete(cacheName)
|
||||
}
|
||||
})
|
||||
);
|
||||
)
|
||||
})
|
||||
)
|
||||
);
|
||||
)
|
||||
|
||||
// The fetch handler serves responses for same-origin resources from a cache.
|
||||
// If no response is found, it populates the runtime cache with the response
|
||||
// from the network before returning it to the page.
|
||||
self.addEventListener('fetch', event => {
|
||||
// Skip cross-origin requests, like those for Google Analytics.
|
||||
if (event.request.url.startsWith(self.location.origin) && event.request.method == "GET") {
|
||||
|
||||
if (
|
||||
event.request.url.startsWith(self.location.origin) &&
|
||||
event.request.method == 'GET'
|
||||
) {
|
||||
// Open the cache
|
||||
event.respondWith(caches.open(CURRENT_CACHE + getApiKey(event.request)).then((cache) => {
|
||||
// Go to the network first
|
||||
return fetch(event.request).then((fetchedResponse) => {
|
||||
cache.put(event.request, fetchedResponse.clone());
|
||||
event.respondWith(
|
||||
caches.open(CURRENT_CACHE + getApiKey(event.request)).then(cache => {
|
||||
// Go to the network first
|
||||
return fetch(event.request)
|
||||
.then(fetchedResponse => {
|
||||
cache.put(event.request, fetchedResponse.clone())
|
||||
|
||||
return fetchedResponse;
|
||||
}).catch(() => {
|
||||
// If the network is unavailable, get
|
||||
return cache.match(event.request.url);
|
||||
});
|
||||
}));
|
||||
return fetchedResponse
|
||||
})
|
||||
.catch(() => {
|
||||
// If the network is unavailable, get
|
||||
return cache.match(event.request.url)
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
@@ -704,8 +704,9 @@ new Vue({
|
||||
})
|
||||
|
||||
if (navigator.serviceWorker != null) {
|
||||
navigator.serviceWorker.register('/service-worker.js')
|
||||
.then(function(registration) {
|
||||
console.log('Registered events at scope: ', registration.scope);
|
||||
});
|
||||
}
|
||||
navigator.serviceWorker
|
||||
.register('/service-worker.js')
|
||||
.then(function (registration) {
|
||||
console.log('Registered events at scope: ', registration.scope)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user