cha*_*ars 7 deployment web vue.js nuxt.js
使用 Nuxt 时,我会提出问题。
当我分发我构建的网站时,缓存问题导致其出现故障。有以下两种情况。有什么办法可以解决吗?
如果构建的话,js和css的文件名会被重命名为hash值,但是在浏览器中查看旧的缓存并没有反映出来。
使用 vue-native webview 创建应用程序应用程序中的 webview 查找旧缓存。要应用改变后的js、css,如何去掉过去的缓存呢?
https://github.com/nuxt/nuxt.js/issues/4764#issuecomment-713469389 这个的实现:
添加插件文件名route.client.js
包含在nuxt.config.json中
function getClientAppVersion() {
return localStorage.getItem('APP_VERSION') ?? 0
}
function setClientAppVersion(version) {
return localStorage.setItem('APP_VERSION', version)
}
export default ({ app }) => {
app.router.afterEach((to, from) => {
fetch("/version.json").then((serverPromise) =>
serverPromise.json().then((response) => {
const latestVersion = response.version
const clientStoredVersion = getClientAppVersion()
if (clientStoredVersion != latestVersion) {
window.location.reload(true)
setClientAppVersion(latestVersion)
}
else return
}))
})}
Run Code Online (Sandbox Code Playgroud)
添加version.jon文件
{
"version": "9.1"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5606 次 |
| 最近记录: |