如果我们将本地构建项目上传到服务器,则不会触发 Angular Service Worker SwUpdate.available

问题描述

当我们的 Angular PWA 有可用的新更新时,我们会显示一个底部表格。它位于 SwUpdate.available 方法中。 SwUpdate.available 仅在我们在服务器中运行构建命令时触发。如果我们在本地运行 build 命令并将文件上传到服务器,则不会发生任何事情。由于我们的服务器内存较少,因此构建命令在服务器上的大部分时间都会失败。

@Component({
  selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.scss'],})
export class AppComponent implements OnInit {
 
  constructor(
    private swUpdate: SwUpdate,private _bottomSheet: MatBottomSheet,) {
    this.checkForUpdates();
  }

  ngOnInit() {}
  
  checkForUpdates() {
    this.swUpdate.available.subscribe(event => {
      this.swUpdate.activateUpdate().then(() => {
        this.openBottomSheet();
      });
    });
  }

  openBottomSheet(): void {
    this._bottomSheet.open(UpdateBottomSheetComponent);
  }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)