首页 > 解决方案 > 托管在 Firebase 上的 Ionic 应用程序需要清除缓存

问题描述

我在 firebase 上托管了一个 ionic 4 应用程序,当我推送更新时,我的用户必须清除他们的缓存才能加载该应用程序的最新版本。

我搜索了一下并修改了我firebase.json的以反映以下内容:

{
  "hosting": {
    "public": "www",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "headers": [
      { "source":"/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}] }
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

我认为这行得通,但今天我推送了更新,它要求我清除缓存。有人对如何强制更新有其他想法吗?

标签: firebaseionic-frameworkcachingfirebase-hosting

解决方案


尝试改变这个

"headers": [{"key": "Cache-Control", "value": "no-cache"}] 

对此

"headers": [{"key": "Cache-Control",  "value": "no-cache, no-store, must-revalidate"]

或这个

"headers": [{"key": "Cache-Control", "value": "public, max-age=0"}]

另外,您正在为 设置规则"source" : "/service-worker.js",这是您想要的吗?

我想你想要这个:

"headers": [
  {
    "source": "/**",
    "headers": [
      {
        "key": "Cache-Control",
        "value": "no-cache, no-store, must-revalidate"
      }
    ]
  }]

看看他们在这个答案中做了什么

这可能会降低用户的性能


推荐阅读