Angular Service Worker未缓存index.html问题求助
Angular Service Worker 未缓存index.html(仅outputPath在Git/NX目录内时触发)
我的Angular应用离线状态下无法正常运行,核心问题是Angular Service Worker没有缓存index.html文件——但js、css、manifest及ico文件都能被正常缓存。
这个问题有明确的触发条件:只有当项目的outputPath设置在Git/NX仓库目录内部时才会出现;如果把outputPath改到仓库目录之外,index.html就能被正常缓存,这个差异可以在Chrome的缓存存储中清晰观察到。
我的ngsw-config.json配置如下:
{ "$schema": "../../../node_modules/@angular/service-worker/config/schema.json", "index": "/index.html", "assetGroups": [ { "name": "app", "installMode": "prefetch", "resources": { "files": [ "/favicon.ico", "/index.html", "/manifest.webmanifest", "/*.css", "/*.js" ] } } ] }
查看NGSW调试信息,没有发现任何错误:
NGSW Debug Info: Driver version: 15.2.7 Driver state: NORMAL ((nominal)) Latest manifest hash: d00a80d860dae8cade766b28147236c702b1e264 Last update check: never === Version d00a80d860dae8cade766b28147236c702b1e264 === Clients: 077bde91-523b-4306-aa45-392b39fc200f === Idle Task Queue === Last update tick: 1s11u Last update run: never Task queue: * init post-load (update) * init post-load (cleanup) * initialization(d00a80d860dae8cade766b28147236c702b1e264) * activate: cleanup-old-sw-caches Debug log:
目前将outputPath设置到仓库外是临时解决方案,但在CI/CD流程中这么做会带来问题。有没有人遇到过类似的情况?该如何进一步排查Service Worker的这种异常?
内容的提问来源于stack exchange,提问作者JonasK
相关产品推荐
相关产品推荐

