微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Angular PWA Service Worker 不缓存离线请求

如何解决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 举报,一经查实,本站将立刻删除。