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

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

问题描述

我有一个使用 create-react-app 构建的网站,并托管在Firebase托管上。我该怎么做才能指定在新部署后需要更新浏览器缓存,并且理想情况下仅对自上次部署以来已更改的页面,资产和样式表进行更新?

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并将其(或任何其他唯一标识符)包含在标头中,以便浏览器可以将其与本地存储或缓存中的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] 不会' t似乎很理想,因为它无视下一次部署的时间(除非有固定的时间表,否则开始时可能是未知的。)。

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 文件305592301 rel = noreferrer>此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天全站免登陆