【问题标题】:Cache-Control header in firebase.json not workingfirebase.json 中的 Cache-Control 标头不起作用
【发布时间】:2016-06-30 05:39:33
【问题描述】:

firebase.json 中的 Cache-Control 标头似乎不起作用。所有文件的max-age 值都设置为31536000(1 年),但在加载页面时仍设置为浏览器默认值3600(1 小时)。

firebase.json 文件似乎遵守firebase documentation.

{
    "hosting": {
        "public": "public"
    },
    "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
    ],
    "headers": [{
        "source": "**",
        "headers": [{
            "key": "Cache-Control",
            "value": "max-age=31536000"
        }]
    }]
}

【问题讨论】:

    标签: json caching firebase cache-control firebase-hosting


    【解决方案1】:

    根据full page的配置,你必须先设置hosting key

    这必须工作:

    {
      "hosting": {
        "public": "app",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ],
        "headers": [{
          "source" : "**",
          "headers" : [{
            "key" : "Cache-Control",
            "value" : "max-age=31536000"
          }]
        }]
      }
    }
    

    【讨论】:

    • 我为标题做了这个,我必须努力刷新才能看到我的 index.html 更改
    • 嗨,哥们,要避免这个问题,您可以disable your cache 或者如果您已经在生产中但您必须在短时间内进行一些更改,您可以设置max-age=3600 这样浏览器将请求新的每小时的数据。
    • 我正在使用 Angular 2,我的目标是防止我的客户不得不硬刷新
    • 我将最大年龄设置为 0,但它们仍然需要硬刷新。
    • 如何防止这种情况发生?
    【解决方案2】:

    想要防止缓存的,应该no-cachemax-age=0一起使用。

    no-store 指令将阻止新资源被缓存,但它不会阻止缓存响应由于先前请求而缓存的非陈旧资源。设置 max-age=0 也会强制缓存重新验证(清除缓存)。

    "headers": [{
      "source" : "**",
      "headers" : [{
        "key" : "Cache-Control",
        "value" : "no-store, max-age=0"
      }]
    }]
    

    【讨论】:

      猜你喜欢
      • 2013-03-30
      • 1970-01-01
      • 2014-01-16
      • 2011-07-20
      • 1970-01-01
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多