Skip to content

Commit 979f86c

Browse files
authoredJul 17, 2024
fix: avoid caching pageviews data (cotes2020#1849)
1 parent 8c30f0a commit 979f86c

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed
 

‎_javascript/pwa/sw.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,23 @@ import { baseurl } from '../../_config.yml';
33
importScripts(`${baseurl}/assets/js/data/swconf.js`);
44

55
const purge = swconf.purge;
6+
const interceptor = swconf.interceptor;
67

78
function verifyUrl(url) {
8-
const requestPath = new URL(url).pathname;
9+
const requestUrl = new URL(url);
10+
const requestPath = requestUrl.pathname;
911

10-
for (const path of swconf.denyPaths) {
12+
if (!requestUrl.protocol.startsWith('http')) {
13+
return false;
14+
}
15+
16+
for (const prefix of interceptor.urlPrefixes) {
17+
if (requestUrl.href.startsWith(prefix)) {
18+
return false;
19+
}
20+
}
21+
22+
for (const path of interceptor.paths) {
1123
if (requestPath.startsWith(path)) {
1224
return false;
1325
}

‎assets/js/data/swconf.js

+18-8
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,24 @@ const swconf = {
2222
{% endfor %}
2323
],
2424

25-
{%- comment -%} The request url with below path will not be cached. {%- endcomment -%}
26-
denyPaths: [
27-
{% for path in site.pwa.cache.deny_paths %}
28-
{% unless path == empty %}
29-
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
30-
{% endunless %}
31-
{% endfor %}
32-
],
25+
interceptor: {
26+
{%- comment -%} URLs containing the following paths will not be cached. {%- endcomment -%}
27+
paths: [
28+
{% for path in site.pwa.cache.deny_paths %}
29+
{% unless path == empty %}
30+
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
31+
{% endunless %}
32+
{% endfor %}
33+
],
34+
35+
{%- comment -%} URLs containing the following prefixes will not be cached. {%- endcomment -%}
36+
urlPrefixes: [
37+
{% if site.analytics.goatcounter.id != nil and site.pageviews.provider == 'goatcounter' %}
38+
'https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/'
39+
{% endif %}
40+
]
41+
},
42+
3343
purge: false
3444
{% else %}
3545
purge: true

0 commit comments

Comments
 (0)