问题描述
我正在尝试使用 Angular Service Worker,一切正常,除了 dataGroups
对我不起作用.
I'm trying to use Angular Service Worker, everything works fine except the dataGroups
not working for me.
这就是我的 ngsw-config.json
:
{
...
"dataGroups": [
{
"name": "api-performance",
"urls": [
"/shipments/**"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
}
]
}
在我的网络选项卡中,我看到服务工作者总是进行服务器调用,然后回退到缓存.见附图.
In my network tab I see that the service worker always make the server call then falls back to the cache. see attached image.
注意我调用的 API 在不同的服务器上,localhost vs some-server:8000,我尝试了不同的使用不同的 URL:"/shipments/**"
/shipments"
"http:some-server:8000/shipments/**"
等,但都没有工作.
Notice the API I'm calling are on a different server, localhost vs some-server:8000,I tried different using different URLs:"/shipments/**"
"/shipments"
"http:some-server:8000/shipments/**"
etc. but none worked.
我的环境:
- @angular 5.1.1
- 服务工作者 5.1.2
- Angular-Cli 1.6.0
推荐答案
我找到了解决方案,我的 api 和 ui 不在同一台服务器上,在同一台服务器上更改它们并将配置更新为代码后波纹管,并在我的网站上使用 HTTPS,一切正常:
I found a solution to this, my api and ui were not on the same server, after changing them on the same one, and updating the config to the code bellow, and using HTTPS on my site, everything worked perfectly:
"dataGroups": [
{
"name": "api-performance",
"urls": [
"/shipments"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
}
]
这篇关于Angular Service Worker - 数据组不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!