Nad*_*lta 6 angular-cli angular angular5 angular-service-worker
我正在尝试使用Angular Service Worker,除了dataGroups不适合我之外,一切正常.
这就是我的意思ngsw-config.json:
"dataGroups": [
{
"name": "api-performance",
"urls": [
"/shipments/**"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
}
]
Run Code Online (Sandbox Code Playgroud)
在我的网络选项卡中,我看到服务工作者总是进行服务器调用然后回退到缓存.见附图.
请注意,我正在调用的API位于不同的服务器上,localhost vs some-server:8000,我尝试了不同的使用不同的URL:
"/shipments/**"
"/shipments"
"http:some-server:8000/shipments/**"....等但没有一个工作.
我的环境:
- @angular 5.1.1
- Service-Worker 5.1.2
- Angular-Cli 1.6.0
谢谢
我找到了一个解决方案,我的 api 和 ui 不在同一台服务器上,在同一台服务器上更改它们并将配置更新为以下代码后,并在我的网站上使用 HTTPS,一切正常:
"dataGroups": [
{
"name": "api-performance",
"urls": [
"/shipments"
],
"cacheConfig": {
"strategy": "performance",
"maxSize": 100,
"maxAge": "3d"
}
}
]
Run Code Online (Sandbox Code Playgroud)