【问题标题】:Firebase hosting no-cache for Angular 5 appFirebase 为 Angular 5 应用托管无缓存
【发布时间】:2018-04-15 22:30:35
【问题描述】:

我试图让我的 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"
  }
}

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

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

【问题讨论】:

    标签: angular firebase firebase-hosting


    【解决方案1】:

    好的,我想通了。在运行 ng build 时,我没有使用 -prod 标志,因此 js 和 css 包没有将哈希添加到它们的名称中(即 main.bf49565a4e90c0772548.bundle.js),因此这些文件仍在缓存中。

    【讨论】:

      猜你喜欢
      • 2018-05-07
      • 2016-12-05
      • 2018-07-25
      • 1970-01-01
      • 2020-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      相关资源
      最近更新 更多