Skip to content

Commit 5911624

Browse files
committed
fix: prevent pageview requests caching
1 parent 8c30f0a commit 5911624

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

_javascript/pwa/sw.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@ importScripts(`${baseurl}/assets/js/data/swconf.js`);
55
const purge = swconf.purge;
66

77
function verifyUrl(url) {
8-
const requestPath = new URL(url).pathname;
8+
const requestUrl = new URL(url);
9+
const requestPath = requestUrl.pathname;
10+
11+
if (!requestUrl.protocol.startsWith('http')) {
12+
return false;
13+
}
14+
15+
for (const denyUrl of swconf.denyUrls) {
16+
if (requestUrl.href.startsWith(denyUrl)) {
17+
return false;
18+
}
19+
}
920

1021
for (const path of swconf.denyPaths) {
1122
if (requestPath.startsWith(path)) {

assets/js/data/swconf.js

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ const swconf = {
2222
{% endfor %}
2323
],
2424

25+
{%- comment -%} The request url starting with below part will not be cached. {%- endcomment -%}
26+
denyUrls: [
27+
{% if site.analytics.goatcounter.id != nil and site.pageviews.provider == 'goatcounter' %}
28+
'https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/'
29+
{% endif %}
30+
],
31+
2532
{%- comment -%} The request url with below path will not be cached. {%- endcomment -%}
2633
denyPaths: [
2734
{% for path in site.pwa.cache.deny_paths %}

0 commit comments

Comments
 (0)