angular 6 service worker dataGroups 不工作 [英] angular 6 service worker dataGroups not working

查看:27
本文介绍了angular 6 service worker dataGroups 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试部署一个后台 Service Worker,在这种情况下,它会在 3 秒的某个时间间隔内调用 api,但它接缝不起作用,当我转到应用程序时,我没有收到对服务器的请求.

Hi I am trying to deploy a background Service worker that makes calls to api in some time interval in this case 3s, but it seams not to work, when I go to application I am getting no requests to server.

我在 ngsw-config.json 中的数据组:

My data group in ngsw-config.json stands:

  "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 行中有:

And when I do http-server -p 8090 web page works, but not sending any requests, I have in my app.module.ts line:

ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production })

在 app.json 中:

and in app.json:

在我的角度 json

in my angular json

"serviceWorker": true

我已通过 ng add @angular/pwa@0.6.8 将该服务工作者添加到现有的 Angular 应用程序

I've added that service worker to existing angular application by ng add @angular/pwa@0.6.8

那我错过了什么?

推荐答案

当您使用 Service Worker 时,它们在您的情况下充当缓存级别.这意味着它将在您配置它们时缓存或执行.
它不会仅从您的配置中自行完成,您必须实际从 api 获取 HTTP 调用.您想查看官方文档中的 service-worker-communications.

When you are using the service workers, they acting in your case as a cache level. which means that it will cache or preform as you configure them to.
It won't do it by it self just from your configuration, you have to actually get the HTTP Calls from the api. You wanna take a look service-worker-communications from the official docs.

简而言之,您必须创建一个新服务,该服务使用 SwUpdate 服务,并且在您的情况下,可能会注册一个间隔,以便从API,并检查您的软件是否有效.

In short, you have to create a new service, which consume the SwUpdate service, and in your case, maybe register an interval which will get the data from the API, and check if your SW works.

这篇关于angular 6 service worker dataGroups 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆