Skip to content

Commit

Permalink
fix: prevent pageview requests caching
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfux committed Jul 17, 2024
1 parent 8c30f0a commit 5911624
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 12 additions & 1 deletion _javascript/pwa/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 7 additions & 0 deletions assets/js/data/swconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down

0 comments on commit 5911624

Please sign in to comment.