fix: avoid caching pageviews data (#1849)
This commit is contained in:
parent
8c30f0a9c3
commit
979f86cf64
2 changed files with 32 additions and 10 deletions
|
@ -3,11 +3,23 @@ import { baseurl } from '../../_config.yml';
|
||||||
importScripts(`${baseurl}/assets/js/data/swconf.js`);
|
importScripts(`${baseurl}/assets/js/data/swconf.js`);
|
||||||
|
|
||||||
const purge = swconf.purge;
|
const purge = swconf.purge;
|
||||||
|
const interceptor = swconf.interceptor;
|
||||||
|
|
||||||
function verifyUrl(url) {
|
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')) {
|
||||||
|
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)) {
|
if (requestPath.startsWith(path)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,14 +22,24 @@ const swconf = {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
],
|
],
|
||||||
|
|
||||||
{%- comment -%} The request url with below path will not be cached. {%- endcomment -%}
|
interceptor: {
|
||||||
denyPaths: [
|
{%- comment -%} URLs containing the following paths will not be cached. {%- endcomment -%}
|
||||||
{% for path in site.pwa.cache.deny_paths %}
|
paths: [
|
||||||
{% unless path == empty %}
|
{% for path in site.pwa.cache.deny_paths %}
|
||||||
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
|
{% unless path == empty %}
|
||||||
{% endunless %}
|
'{{ path | relative_url }}'{%- unless forloop.last -%},{%- endunless -%}
|
||||||
{% endfor %}
|
{% 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
|
purge: false
|
||||||
{% else %}
|
{% else %}
|
||||||
purge: true
|
purge: true
|
||||||
|
|
Loading…
Reference in a new issue