Firebase托管Angular 5 app的无缓存

时间:2018-04-15 22:30:36

标签: angular firebase firebase-hosting

我试图让我的Angular应用程序的索引页面不要缓存。我根据this post格式化了我的firebase.json规则:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": "npm --prefix functions run build"
  },
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ],
    "headers" : [{
      "source": "/**",
      "headers": [
        {
          "key": "Cache-Control",
          "value": "no-cache, no-store, must-revalidate"
        }
      ]
    },
      {
        "source":
        "**/*.@(jpg|jpeg|gif|png|svg|js|css|eot|otf|ttf|ttc|woff|font.css)",
        "headers": [
          {
            "key": "Cache-Control",
            "value": "max-age=604800"
          }
        ]
      }]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

如果我检查浏览器控制台,似乎规则正常:

firebase no cache result

但是,它仍然在加载过时的文件,我需要重新加载才能看到更改。知道问题是什么吗?

1 个答案:

答案 0 :(得分:0)

好的我明白了。我在运行asScala时没有使用-prod标志,因此js和css包没有在其名称中添加哈希值(即ng build),因此这些文件仍在缓存中