通过 sw-precache 在已经版本化的包文件上缓存破坏

Cache busting through sw-precache on already versioned bundle files

我正在使用 sw-precache 来允许预缓存 Angular 应用程序的所有静态资源。我明白 sw-precache concept of versioning by calculating the MD5 hash which is used to determine whether the file has changed or not.

但我想知道我们将如何处理 versioning/cache 破坏通过 sw-precache 捆绑文件(比如 bundle.877095ebde8.js),这些文件是通过连接多个文件并缩小它们和版本控制生成的文件。

因为在这种情况下,每次您进行任何更改并创建新的版本控制文件时,整个文件都会更改,而不是文件内容,因此 navigator.serviceWorker.controller 始终 returns 为空。

服务worker.controller 不会总是空的。当您更改这些文件时,Sw-precache 将为您构建一个新的服务工作者,浏览器将更新以使用新的服务工作者。

当然,在这种情况下,感觉 sw-precache 可能会有更智能的版本控制 - 可能会在 repo 上提出问题。