feat: 添加 Service Worker 缓存与更新流程

- 为同源资源添加网络优先策略,并在离线时回退到缓存
- 缓存带版本号的 CDN 资源,并在发布更新时保留独立缓存条目
- 改进版本更新检查,避免清除 localStorage 或无关缓存
- 将 Service Worker 纳入部署流程并更新相关文档
This commit is contained in:
eddy
2026-07-20 02:22:15 +08:00
parent a878899512
commit 738275b493
6 changed files with 226 additions and 16 deletions
+4 -4
View File
@@ -85,18 +85,18 @@ deploy() (
fi
source_dir=$(find "$temp_dir" -mindepth 2 -maxdepth 2 -type d -name src -print -quit)
if [[ -z "$source_dir" || ! -f "$source_dir/index.html" || ! -d "$source_dir/js" || ! -d "$source_dir/styles" ]]; then
print_error "仓库中缺少 src/index.html、src/js 或 src/styles,已取消部署"
if [[ -z "$source_dir" || ! -f "$source_dir/index.html" || ! -f "$source_dir/sw.js" || ! -d "$source_dir/js" || ! -d "$source_dir/styles" ]]; then
print_error "仓库中缺少 src/index.html、src/sw.js、src/js 或 src/styles,已取消部署"
return 1
fi
clear_target
print_info "正在拷贝网站文件到 $TARGET_DIR ..."
cp -a "$source_dir/index.html" "$source_dir/js" "$source_dir/styles" "$TARGET_DIR/"
cp -a "$source_dir/index.html" "$source_dir/sw.js" "$source_dir/js" "$source_dir/styles" "$TARGET_DIR/"
print_success "部署完成"
print_info "已部署: index.html、js/、styles/"
print_info "已部署: index.html、sw.js、js/、styles/"
print_info "已保留: $TARGET_DIR/$PRESERVED_NAME/"
)