服务工作者缓存超时错误

时间:2019-08-06 19:36:32

标签: angular service-worker progressive-web-apps

我已将我的角度应用程序设置为PWA,并且启用了Service Worker。我注意到,即使我再次启动该服务,某些呼叫仍会失败。查看“网络”选项卡时,我注意到该呼叫返回了504超时,并在其旁边说(来自serviceworker)。

我尝试编辑ngsw-config文件以添加一个dataGroup,并且将策略设置为“ freshness”,但是它仍然没有帮助。请注意,我在dataGroups下添加的URL旨在指向外部URL,因此我将**/Client/**

我拥有的配置文件:

{
  "index": "/index.html",
  "dataGroups": [
    {
      "name": "api-performance",
      "urls": ["/assets/i18n/**", "/api/**"],
      "cacheConfig": {
        "strategy": "performance",
        "maxSize": 100,
        "maxAge": "3d"
      }
    },
    {
      "name": "api-freshness",
      "urls": [
        "**/Client/**",
        "/dashboard",
        "/dashboard/**"
      ],
      "cacheConfig": {
        "strategy": "freshness",
        "maxSize": 100,
        "maxAge": "3d",
        "timeout": "10s"
      }
    },
    {
      "name": "cms",
      "urls": ["http://localhost:3000/**"],
      "cacheConfig": {
        "maxSize": 0,
        "maxAge": "0u",
        "strategy": "freshness"
      }
    }
  ],
  "assetGroups": [
    {
      "name": "app",
      "installMode": "prefetch",
      "resources": {
        "files": ["/favicon.ico", "/index.html", "/*.css", "/*.js"],
        "urls": [
        ]
      }
    },
    {
      "name": "assets",
      "installMode": "lazy",
      "updateMode": "prefetch",
      "resources": {
        "files": [
          "/assets/**",
          "/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ]
      }
    }
  ]
}

对于任何api调用,我都希望服务人员尝试获取最新的并且仅在最后结果的情况下才还原到缓存。

0 个答案:

没有答案