Firebase托管Flutter Web App无法清除首次部署的缓存

Firebase托管Flutter Web App无法清除首次部署的缓存

问题描述:

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

We build a flutter web app and deployed it via firebase hosting. Unfortunately, we didnt configure any caching settings in our initial deploy.

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

Now we deployed a newer version of our website but people still get the old website shown form the first deploy. What we tried so far:

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

Adding version no. to our index.html:

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

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

Adding meta Data in our header in 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" />

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

In our firebase.json we added the following headers:

"headers": [
      {
        "source": "**",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=10"
          }
        ]
      }
    ]

所有这些尝试都没有运气,我们认为问题在于较新的版本没有文件中有这些条目。我们如何强制更新到我们的最新版本?

All of these attemps were without any luck. We think that the problem is that the newer version doesnt have those entries in the files. How can we force this to update to our newest version? We even consider opening a new firebase project if that might help.

非常感谢您的帮助!

尝试以下操作:

在flutter应用中,在Web文件夹内的index.html中,在 src = main.dart.js

In your flutter app, in the index.html within the web folder, add a version number after the src="main.dart.js

所以您的新行将如下所示:

So your new line will look like this:

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

然后在每次构建之前将版本号增加到2,以此类推。

Then increment the version number to 2, etc before you do each build.