1
0
mirror of https://github.com/cotes2020/jekyll-theme-chirpy.git synced 2026-03-26 21:08:12 +00:00

refactor!: optimize the resource hints (#1717)

Improved the data structure for defining resource hints to the browser.
This commit is contained in:
Cotes Chung
2024-05-02 05:11:45 +08:00
committed by GitHub
parent f1c6d2a817
commit dcb0add47b
4 changed files with 28 additions and 64 deletions

View File

@@ -9,21 +9,7 @@ const swconfUrl = '{{ '/assets/js/data/swconf.js' | relative_url }}';
importScripts(swconfUrl);
const purge = swconf.purge;
function verifyHost(url) {
for (const host of swconf.allowHosts) {
const regex = RegExp(`^http(s)?://${host}/`);
if (regex.test(url)) {
return true;
}
}
return false;
}
function verifyUrl(url) {
if (!verifyHost(url)) {
return false;
}
const requestPath = new URL(url).pathname;
for (const path of swconf.denyPaths) {
@@ -34,10 +20,6 @@ function verifyUrl(url) {
return true;
}
if (!purge) {
swconf.allowHosts.push(location.host);
}
self.addEventListener('install', (event) => {
if (purge) {
return;