Firebase 托管 - 强制浏览器在新部署时重置缓存? [英] Firebase hosting - force browser to reset cache on new deploys?

查看:15
本文介绍了Firebase 托管 - 强制浏览器在新部署时重置缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 create-react-app 构建并托管在 Firebase Hosting 上的网站.我可以做些什么来指定在新部署后需要更新浏览器缓存,理想情况下仅适用于自上次部署以来已更改的页面、资产和样式表?

I have a site built with create-react-app and hosted on Firebase Hosting. What can I do to specify the browser cache needs to be updated after new deploys, and ideally only for pages, assets, and stylesheets that have been changed since the last deploy?

有没有办法访问部署 ID 并将其(或任何其他唯一标识符)包含在标头中,以便浏览器可以与本地存储或缓存中的内容进行比较,并确定是否需要硬刷新?我查看了 Firebase 部署 以及 完整配置 文档,但没有提及如何访问托管元数据,例如上次部署时间.

Is there a way to access the deploy id and include that (or any other unique identifier) in the headers so the browser can compare to what it has in local storage or cache and determine whether a hard refresh is necessary? I looked over the Firebase Deploying as well as Full config docs but there's no mention on how to access hosting metadata like the last deploy time.

Cache-Control 值设置为 max-age=[any number] 似乎并不理想,因为它忽略了下一次部署的时间(可能是除非有固定的时间表,否则一开始不知道).

Setting a Cache-Control value to max-age=[any number] doesn't seem ideal because it disregards when the next deployment will occur (which might be unknown to begin with unless there are regular schedules).

推荐答案

我想通了.必须根据 firebase.json 文件">此 Github 评论:

I figured it out. Had to update the firebase.json file according to this Github comment:

{
  "hosting": {
    "headers": [
      { "source":"/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}] }
    ]
  }
}

这篇关于Firebase 托管 - 强制浏览器在新部署时重置缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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