From af27d9575b7001b3ee1810d5f6181b29b0492d5d Mon Sep 17 00:00:00 2001 From: hehh Date: Tue, 25 Nov 2025 18:36:52 +0800 Subject: [PATCH] =?UTF-8?q?feat(pwa):=20=E4=BC=98=E5=8C=96PWA=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=92=8C=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新HTML文件中的PWA相关meta标签和图标路径 - 调整Service Worker缓存资源路径为相对路径 - 增强Service Worker fetch事件处理逻辑 - 升级缓存版本号以确保更新生效 - 优化Google Analytics脚本加载方式 - 整理HTML文件结构,提升可读性 --- about.html | 4 +- index.html | 144 ++++++++++++++++++++++++++++------------------------- js/sw.js | 24 +++++---- 3 files changed, 93 insertions(+), 79 deletions(-) diff --git a/about.html b/about.html index c107ec6..e5c6d03 100644 --- a/about.html +++ b/about.html @@ -450,10 +450,10 @@ - + - + diff --git a/index.html b/index.html index 22c51d3..1e3deed 100644 --- a/index.html +++ b/index.html @@ -12,33 +12,36 @@ - + - + - + - + - + - + - - + + Honesty的主页 @@ -58,7 +61,6 @@ media="all"> - - + gtag('js', new Date()); + } catch (e) { + console.log("Google Analytics Init 错误", e); + } - - + - - + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/sw.js b/js/sw.js index 6824be2..fb9d8db 100644 --- a/js/sw.js +++ b/js/sw.js @@ -1,15 +1,14 @@ // Service Worker for PWA -const CACHE_NAME = 'honesty-home-v1.0.0'; +const CACHE_NAME = 'honesty-home-v1.0.1'; const urlsToCache = [ - '/', - '/index.html', - '/about.html', - '/css/style.css', - '/css/about.css', - '/css/artalk.css', - '/js/config.js', - '/js/main.js', - '/js/about.js' + './index.html', + './about.html', + './css/style.css', + './css/about.css', + './css/artalk.css', + './js/config.js', + './js/main.js', + './js/about.js' ]; // 安装事件 - 缓存资源 @@ -25,6 +24,11 @@ self.addEventListener('install', event => { // 获取事件 - 拦截网络请求 self.addEventListener('fetch', event => { + // 对于非GET请求或者不是同源请求,直接跳过 + if (event.request.method !== 'GET' || !event.request.url.startsWith(self.location.origin)) { + return; + } + event.respondWith( caches.match(event.request) .then(response => {