Firebase 托管 Flutter Web 应用程序未清除首次部署的缓存 [英] Firebase Hosting Flutter Web App not clearing Cache of first deploy

查看:32
本文介绍了Firebase 托管 Flutter Web 应用程序未清除首次部署的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们构建了一个 Flutter 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"
          }
        ]
      }
    ]

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

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:

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆