【发布时间】:2019-01-07 21:06:51
【问题描述】:
您好,我正在尝试部署一个后台 Service Worker,它在这种情况下 3 秒内以某个时间间隔调用 api,但它似乎无法正常工作,当我转到应用程序时,我没有收到对服务器的请求。
我在 ngsw-config.json 中的数据组代表:
"dataGroups": [
{
"name": "app-service-list",
"urls": [ "http://localhost:5000/api/TcpCommunication/GetCabinsService" ],
"cacheConfig": {
"maxSize": 5,
"maxAge": "3s",
"strategy": "performance"
}
}
]
当我做 http-server -p 8090 网页工作,但不发送任何请求时, 我的 app.module.ts 行中有:
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })
在 app.json 中:
在我的角度 json 中
"serviceWorker": true
我已经通过 ng add @angular/pwa@0.6.8 将该服务工作者添加到现有的 Angular 应用程序中
那么我错过了什么?
【问题讨论】:
-
不确定您要达到的目标,但 dataGroups 不会预取请求。
-
我需要一些独立于 UI 的东西,每 3 分钟向 api 询问一些信息:
-
你应该为此创建一个服务。
-
只有你可以预取的assetGroups,它会在应用加载时缓存资源。数据组真的很懒惰。
标签: angular service-worker angular6