javascript - Angular PWA 服务工作者没有离线缓存请求
问题描述
我正在构建一个带有 node.js 后端的 Angular PWA。我已经添加了@angular/pwa,并且资产离线可用。
我配置了两条路线:
- /api/验证
- /api/分数
不幸的是,我的请求没有离线存储。
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"
}
}
]
}
一旦我离线,我就没有收到服务人员的回复。浏览器的缓存存储中有名为api-freshness和api-performance的存储。但它们是空的。
解决方案
推荐阅读
- javascript - 如何使用客户端库从节点 js 将文件夹上传到 GCS
- typescript - 如何将数据保存在我的全局变量中(未定义的值)
- delphi - Steema TeeChart 单杠系列。如何使用 Stacked100?
- c# - HTTP_X_FORWARDED_FOR 仅适用于 http 而不是 https
- python - Python 运行时与 C 运行时
- r - R获取与多维列联表中最大值关联的级别
- vue.js - 如何一般地观察多个值或数据变化
- pointers - 接口不能调用self方法
- docker - 为什么 Openshift 镜像流哈希与 Redhat 注册表 API 哈希不同?
- android - 如何在不添加电话/手机号码的情况下添加联系人?