Angular Service Worker-数据组不起作用 [英] Angular Service Worker - dataGroups not working
问题描述
我正在尝试使用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进行了不同:
/装运/ **
/装运
http:some-server:8000 / shipments / **
.... etc但无济于事。
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
My Environment:
- @angular 5.1.1
- Service-Worker 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-数据组不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!