Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid caching pageviews data #1849

Merged
merged 3 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions _javascript/pwa/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ import { baseurl } from '../../_config.yml';
importScripts(`${baseurl}/assets/js/data/swconf.js`);

const purge = swconf.purge;
const interceptor = swconf.interceptor;

function verifyUrl(url) {
const requestPath = new URL(url).pathname;
const requestUrl = new URL(url);
const requestPath = requestUrl.pathname;

for (const path of swconf.denyPaths) {
if (!requestUrl.protocol.startsWith('http')) {
cotes2020 marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

for (const prefix of interceptor.urlPrefixes) {
if (requestUrl.href.startsWith(prefix)) {
return false;
}
}

for (const path of interceptor.paths) {
if (requestPath.startsWith(path)) {
return false;
}
Expand Down
26 changes: 18 additions & 8 deletions assets/js/data/swconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@ const swconf = {
{% endfor %}
],

{%- comment -%} The request url with below path will not be cached. {%- endcomment -%}
denyPaths: [
{% for path in site.pwa.cache.deny_paths %}
{% unless path == empty %}
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
{% endunless %}
{% endfor %}
],
interceptor: {
{%- comment -%} URLs containing the following paths will not be cached. {%- endcomment -%}
paths: [
{% for path in site.pwa.cache.deny_paths %}
{% unless path == empty %}
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
{% endunless %}
{% endfor %}
],

{%- comment -%} URLs containing the following prefixes will not be cached. {%- endcomment -%}
urlPrefixes: [
{% if site.analytics.goatcounter.id != nil and site.pageviews.provider == 'goatcounter' %}
'https://{{ site.analytics.goatcounter.id }}.goatcounter.com/counter/'
{% endif %}
]
},

purge: false
{% else %}
purge: true
Expand Down