简体   繁体   English

当 service worker 检测到变化时立即更新 DOM

[英]Instantly update DOM when service worker detects a change

Is there any way to have service workers fetch the cached version, then attempt to do a.network fetch, and if it's different than the cached version, put that new thing in the cache and replace the old asset in the DOM with the new one instantly (without having to refresh the page)?有什么方法可以让服务人员获取缓存版本,然后尝试进行网络获取,如果它与缓存版本不同,则将新内容放入缓存中,并用新的替换 DOM 中的旧资产立即(无需刷新页面)?

Hey yeah this is a very tricky situation but what I did was save a version number to my.env file on production release.嘿,是的,这是一个非常棘手的情况,但我所做的是在生产发布时将版本号保存到 my.env 文件中。

I then built this NPM package which will surface the Version number of the.env at build time.然后我构建了这个 NPM package 它将在构建时显示 the.env 的版本号。 I could then use this number in my VueJS - PWA to check against the old currently cached version number, and then do a.network request if they dont match.然后我可以在我的 VueJS - PWA 中使用这个数字来检查当前缓存的旧版本号,然后如果它们不匹配则执行网络请求。

https://www.npmjs.com/package/vue-enverywhere https://www.npmjs.com/package/vue-enverywhere

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM