使用 Angular 应用程序运行 Lighthouse 后注册卸载侦听器

Rob*_*ira 9 node.js ionic-framework angular

我使用 Lighthouse 进行了测试并返回了问题 -> 注册卸载侦听器

unload事件不会可靠地触发,监听它会阻止浏览器优化,如后向缓存。考虑改用pagehideorvisibilitychange事件。URL -> polyfills.js: 1747

填充物

chunk {11} polyfills-es5.490b14415b7cca5be47f.js (polyfills-es5) 129 kB [initial] [rendered]
chunk {10} polyfills-es2015.35d05f7e533d01d161a7.js (polyfills) 36.2 kB [initial] [rendered]

Ionic:
   Ionic CLI                     : 5.4.16
   Ionic Framework               : @ionic/angular 5.0.7
   @angular-devkit/build-angular : 0.1002.0
   @angular-devkit/schematics    : 10.1.7
   @angular/cli                  : 10.0.1
   @ionic/angular-toolkit        : 2.3.3

Cordova:
   Cordova CLI       : 10.0.0
   Cordova Platforms : 6.0.0, android 8.1.0, browser, ios 5.1.1
   Cordova Plugins   : not available

Utility:
   cordova-res : not installed
   native-run  : not installed

System:
   NodeJS : v14.15.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.14.8
   OS     : Windows 10
Run Code Online (Sandbox Code Playgroud)

这是我的第一个应用程序,我是开发新手,我没有找到解决这个问题的方法。如何在 polyfill 中应用卸载事件?

Ind*_*ole 4

可能的原因是您的应用程序中安装的第三方库之一正在进行此调用。这个问题已经在Angular GitHub 存储库上进行了讨论,他们已经确认这个调用不是直接来自 Angular。罪魁祸首可能是 fbevents.js(如果您正在使用 Facebook 跟踪)或者您自己在应用程序中使用 window.onunload 事件。

如何查找原因 -> 转到“源”选项卡,右键单击“顶部”并选择“在所有文件中搜索”。

在此输入图像描述

输入addEventListener("unload"这应该告诉您实际导致此问题的原因。 在此输入图像描述