服务人员不应该缓存404响应

时间:2019-06-03 18:57:54

标签: angular angular6 service-worker angular-service-worker

我当前在我的角度应用程序中使用Service Worker,一切工作都很好,但是如果响应为404,我不想缓存,并且如果响应为404,我想在外面打电话

我遵循了https://angular.io/guide/service-worker-intro中提到的所有步骤,并且服务人员正在为我工​​作,但是如果响应为404,则进行缓存。

{
  "index": "/index.html",
  "dataGroups": [
    {
      "name": "test",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "urls": [
        "test/**"
      ],
      "cacheConfig": {
        "maxAge": "5m"
      }
    },
    {
      "name": "test2",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "urls": [
        "https://test/**"
      ],
      "cacheConfig": {
        "maxAge": "30s"
      }
    }
  ]
}

1 个答案:

答案 0 :(得分:0)

也许您可以使用!符号将具有404响应的网址放入您的网址配置中,而忽略该网址

  "urls": [
    "https://test/**",
    "!https://404.html"
  ],