如何将杠杆式浏览器缓存添加到firebase.json

时间:2018-07-04 22:53:07

标签: json firebase firebase-hosting web-site-project

我第一次在Google Cloud Platform上使用Firebase,并且已经上传了静态网站,但现在我想添加:

"headers": [ {
    "source" : "**/*.@(eot|otf|ttf|ttc|woff|font.css)",
    "headers" : [ {
      "key" : "Access-Control-Allow-Origin",
      "value" : "*"
  } ]
  }, {
    "source" : "**/*.@(jpg|jpeg|gif|png)",
    "headers" : [ {
    "key" : "Cache-Control",
    "value" : "max-age=7200"
    } ]
  }, {
    // Sets the cache header for 404 pages to cache for 5 minutes
    "source" : "404.html",
    "headers" : [ {
    "key" : "Cache-Control",
    "value" : "max-age=300"
    } ]
  } ]

启用杠杆浏览器缓存,但是我不明白如何将这些代码行添加到firebase.json文件中? firebase init命令在项目目录的根目录中创建一个firebase.json设置文件,但是创建网站后如何更改它?

非常感谢

1 个答案:

答案 0 :(得分:1)

如果要更改网站上的缓存设置,请在Change-Control中更改相关的firebase.json标头,然后重新运行firebase deploy。这将使用您的新设置部署最新的firebase.json,并确保所有HTML / CSS / JS / etc文件也是最新的。

如果您丢失了firebase.json,则Firebase Hosting reference documentation中的一个简单默认值可能类似于:

{
  "hosting": {
    "public": "app",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}