feat(pwa): 优化PWA配置和缓存策略

- 更新HTML文件中的PWA相关meta标签和图标路径
- 调整Service Worker缓存资源路径为相对路径
- 增强Service Worker fetch事件处理逻辑
- 升级缓存版本号以确保更新生效
- 优化Google Analytics脚本加载方式
- 整理HTML文件结构,提升可读性
This commit is contained in:
hehh
2025-11-25 18:36:52 +08:00
parent f1d4207e35
commit af27d9575b
3 changed files with 93 additions and 79 deletions

View File

@@ -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 => {