Service Worker 生命周期
1. register → 2. install 预缓存 app shell → 3. activate 清理旧缓存 → 4. fetch 拦截请求走缓存策略
register
install
activate
fetch
缓存策略对比
• Cache First:静态资源,快但更新滞后 • Network First:接口数据,实时优先、失败兜底缓存 • Stale-While-Revalidate:先返缓存、后台更新(最佳体验)