Stop saving in cache memory Flutter web Firebase hosting

江枫思渺然 提交于 2021-02-19 02:47:13

问题


I designed a web app using the Flutter web. I hosted it with Firebase host. But It's not showing changes of my code after deploying to firebase. It's still showing my older version of web app. But I can overcome this problem by clearing cache memory of browser or ctrl+refresh. But I don't want to do this every time I deploy to firebase. How to stop saving my web app in cache memory?

hosted link: https://frcovid19dashboard.web.app


回答1:


Append a version number to your main.dart file. Every time you do changes that require the browser to clear cash, change the appended version number before you upload changes so the browser knows something has change and it needs to clear the cash. For example:

First Version:

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

Next time you make changes:

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

And so on. Check this link.




回答2:


Another approach would be to prevent caching via HTTP headers. For Firebase Hosting that would be : https://firebase.google.com/docs/hosting/full-config#headers

I guess you could set up something like this :

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


来源:https://stackoverflow.com/questions/61286756/stop-saving-in-cache-memory-flutter-web-firebase-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!