Firebase 托管 Flutter Web 应用程序未清除首次部署的缓存

Giz*_*zmo 10 hosting caching web firebase flutter

我们构建了一个 Flutter Web 应用程序并通过 Firebase 托管进行部署。不幸的是,我们没有在初始部署中配置任何缓存设置。

现在我们部署了我们网站的更新版本,但人们仍然会从第一次部署中看到旧网站。到目前为止我们尝试过的:

添加版本号 到我们的 index.html:

<"script src="main.dart.js?version=1" type="application/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

在 index.html 的标题中添加元数据:

  <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
  <meta http-equiv="Pragma" content="no-cache" />
  <meta http-equiv="Expires" content="0" />
Run Code Online (Sandbox Code Playgroud)

在我们的 firebase.json 中,我们添加了以下标头:

"headers": [
      {
        "source": "**",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=10"
          }
        ]
      }
    ]
Run Code Online (Sandbox Code Playgroud)

所有这些尝试都没有任何运气。我们认为问题在于较新版本的文件中没有这些条目。我们如何强制它更新到我们的最新版本?如果这可能有帮助,我们甚至考虑开设一个新的 Firebase 项目。

非常感谢您的帮助!

bm8*_*888 12

尝试这个:

在您的 flutter 应用程序中,在 web 文件夹内的 index.html 中,在 src="main.dart.js

所以你的新行看起来像这样:

<script src="main.dart.js?version=1" type="application/javascript"></script>

然后在每次构建之前将版本号增加到 2 等。

2021 年 6 月更新:在 index.html 中添加这一行作为正文中的最后一个脚本

  • 谢谢,我实际上没有在文档中看到,只是假设新部署的版本正在替换来自终端的消息之前的版本“最终版本...”,“版本最终版本”,“发布新版本...”, `发布完成`..现在我才意识到“版本..”哈哈。非常感谢 (2认同)