Firebase 托管正在 CDN 上缓存我的动态“robots.txt”

问题描述

从 Firebase 文档中,我们了解到它应该将 Cache-Control: private 设置为认值。

Firebase Hosting- Manage cache behavior

enter image description here

我即时生成我的 robots.txt,因此它可能会从一个请求更改为下一个请求。因此,我不希望它被 CDN 缓存。但令我惊讶的是,robots.txt 的 CDN 命中率很高。

见:

enter image description here

我对 ads.txtsitemap.xml 也是如此。 ads.txt 也会发生同样的情况,但 sitemap.xml 不会。

可能与 .txt 文件有关。这可能是一个错误吗?

我是否必须明确设置 Cache-Control: private

解决方法

您可以像这样通过 firebase.json 文件配置该特定文件的缓存控制标头:

{
  "hosting": [
    {
      ...,"headers": [
        {
          "source": "robots.txt","headers": [
            {
              "key": "Cache-Control","value": "no-cache"
            }
          ]
        }
      ]
    }
  ]
}

文档 here 中的更多信息。