简体   繁体   English

使用 service worker 预取 API 调用

[英]Prefetch API calls with service worker

I have setup service worker for my angular app.我为我的 angular 应用程序设置了服务人员。 The caching of the data groups works fine as long as the relevant page that the API call is made is visited.只要访问了调用 API 的相关页面,数据组的缓存就可以正常工作。 However my goal is to on the load of the application cache the data of all the endpoints specified in the ngsw-config.但是我的目标是在应用程序的负载上缓存 ngsw-config 中指定的所有端点的数据。 Tried using the example provided for swUpdate that is:尝试使用为 swUpdate 提供的示例,即:

swUpdate.available.subscribe(event => {
      swUpdate.activateUpdate().then(() => document.location.reload());
    }); 

on the start of the application in the constructor of my appcomponent, but no luck.在我的 appcomponent 的构造函数中启动应用程序,但没有运气。 Any help is appreciated.任何帮助表示赞赏。 TIA. TIA。

it need to download metadata from server try as follow它需要从服务器下载元数据尝试如下

    swUpdate.available.subscribe(event => {
      swUpdate.activateUpdate().then(() => document.location.reload());
    });
    if(swUpdate.isEnabled) {
      swUpdate.checkForUpdate();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM