diff --git a/_javascript/pwa/sw.js b/_javascript/pwa/sw.js index bc67bd8307b..d005c520fbc 100644 --- a/_javascript/pwa/sw.js +++ b/_javascript/pwa/sw.js @@ -5,7 +5,18 @@ importScripts(`${baseurl}/assets/js/data/swconf.js`); const purge = swconf.purge; function verifyUrl(url) { - const requestPath = new URL(url).pathname; + const requestUrl = new URL(url); + const requestPath = requestUrl.pathname; + + if (!requestUrl.protocol.startsWith('http')) { + return false; + } + + for (const denyUrl of swconf.denyUrls) { + if (requestUrl.href.startsWith(denyUrl)) { + return false; + } + } for (const path of swconf.denyPaths) { if (requestPath.startsWith(path)) { diff --git a/assets/js/data/swconf.js b/assets/js/data/swconf.js index 5c1ed29205a..ed7286ac2a5 100644 --- a/assets/js/data/swconf.js +++ b/assets/js/data/swconf.js @@ -22,6 +22,13 @@ const swconf = { {% endfor %} ], + {%- comment -%} The request url starting with below part will not be cached. {%- endcomment -%} + denyUrls: [ + {% if site.analytics.goatcounter.id != nil and site.pageviews.provider == 'goatcounter' %} + 'https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/' + {% endif %} + ], + {%- comment -%} The request url with below path will not be cached. {%- endcomment -%} denyPaths: [ {% for path in site.pwa.cache.deny_paths %}