Angular PWA Service Worker 不缓存离线请求

问题描述

我正在构建一个带有 node.js 后端的 Angular PWA。我已经添加了 @angular/pwa 并且资产可以离线使用。

我配置了两条路由:

很遗憾,我的请求没有离线存储。

ngsw-config.json

{
  "$schema": "./node_modules/@angular/service-worker/config/schema.json","index": "/index.html","assetGroups": [
    {
      "name": "app","installMode": "prefetch","resources": {
        "files": [
          "/favicon.ico","/index.html","/manifest.webmanifest","/*.css","/*.js"
        ]
      }
    },{
      "name": "assets","installMode": "lazy","updateMode": "prefetch","resources": {
        "files": [
          "/assets/**","/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
        ]
      }
    }
  ],"dataGroups": [
    {
      "name": "api-performance","urls": [
        "/api/**"
      ],"cacheConfig": {
        "strategy": "performance","maxSize": 200,"maxAge": "5d"
      }
    },{
      "name": "api-freshness","urls": [
        "/api/verify","/api/score"
      ],"cacheConfig": {
        "strategy": "freshness","maxSize": 100,"maxAge": "3d","timeout": "3s"
      }
    }
  ]
}

我一离线,就没有得到 Service Worker 的回复。浏览器的 Cache Storage 中有名为 api-freshnessapi-performance 的存储。但它们是空的。

Network

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)