Skip to content

Commit

Permalink
Exclude path from service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed May 9, 2021
1 parent 50c0618 commit 6155a79
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions template/assets/js/service-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ self.addEventListener("install", (event) => {
const urlsToCache = [
'/',
'/index.js',
'/service-worker.js',
'/offline.html',
'/favicon.ico',
'/icon/favicon-16.png',
'/icon/favicon-32.png',
'/icon/icon-128.png',
Expand Down Expand Up @@ -39,6 +41,14 @@ self.addEventListener('activate', (e) => {
});

self.addEventListener("fetch", (event) => {
if (event.request.url !== '') {
try {
const url = new URL(event.request.url)
if (url.pathname.match('^.*(\/w|\/healthcheck|\/version|\/metrics)$')) {
return false
}
} catch (_) { }
}
event.respondWith(
(async () => {
const cache = await caches.open(CACHE_NAME);
Expand All @@ -57,6 +67,9 @@ function fetchAndCache(url) {
}
return caches.open(CACHE_NAME)
.then(function (cache) {
if (!(url.indexOf('http') === 0)) {
return response;
}
cache.put(url, response.clone());
return response;
});
Expand Down

0 comments on commit 6155a79

Please sign in to comment.