Ced*_*Ced 4 javascript service-worker angular angular5 angular-service-worker
我正在尝试使服务工作者能够与API请求一起工作。我希望该应用离线运行,并具有以下配置:
{
"name": "api",
"urls": ["https://x.com/**"],
"cacheConfig": {
"strategy": "performance",
"maxSize": 20,
"maxAge": "365d",
"timeout": "5s"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我离线时xhr标签的外观:
这是用户请求的内容:
如您所见,用户的API调用无法解析。
这是user在线时的响应:
尝试这个:
从此更改您的DataGroups数组:
{
"name": "api",
"urls": ["https://x.com/**"],
"cacheConfig": {
"strategy": "performance",
"maxSize": 20,
"maxAge": "365d",
"timeout": "5s"
}
}
Run Code Online (Sandbox Code Playgroud)对此:
"dataGroups": [
{
"name": "api-performance",
"urls": [
"/user" //<=========== I know you want all API calls to be cached, but try this first and see
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
}
]
Run Code Online (Sandbox Code Playgroud)
PROD,小智 -2
要离线处理 API 数据,您必须使用离线存储(即在初始 API 调用后将数据存储在 Web 浏览器中),最近我在我的应用程序中使用了 Local Forage。找到下面的链接:
https://github.com/Alorel/ngforage#types-and-polyfills
https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/offline-for-pwa
| 归档时间: |
|
| 查看次数: |
5358 次 |
| 最近记录: |