Use the `beforeunload` event instead of `unload`
authorAlexander Ebert <ebert@woltlab.com>
Thu, 15 Feb 2024 11:49:01 +0000 (12:49 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 15 Feb 2024 11:49:01 +0000 (12:49 +0100)
It pretty much does the same, but does not trigger a pointless warning in PageSpeed insights.

See https://www.woltlab.com/community/thread/304788-page-speed-insights-optimierung-2024/

ts/WoltLabSuite/Core/Ajax/Backend.ts
wcfsetup/install/files/js/WCF.Message.js
wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Backend.js

index c4b4e0dfe0fdd051233ea9845cc806250f57c1e0..be1fcda4be9a06845fdf9327dd84c6e075722d51 100644 (file)
@@ -42,7 +42,7 @@ class SetupRequest {
 }
 
 let ignoreConnectionErrors = false;
-window.addEventListener("unload", () => (ignoreConnectionErrors = true));
+window.addEventListener("beforeunload", () => (ignoreConnectionErrors = true));
 
 class BackendRequest {
   readonly #url: string;
index 6af894f3ffd9c55919ea7999085eb484863e6611..2c086841285d8d1902727457fdd6ea8314ec9dc8 100644 (file)
@@ -240,8 +240,8 @@ WCF.Message.FormGuard = Class.extend({
                });
                
                // restore buttons, prevents disabled buttons on back navigation in Opera
-               $(window).on('unload',function() {
-                       $forms.find('.formSubmit input[type=submit]').enable();
+               $(window).on("beforeunload", function () {
+                       $forms.find(".formSubmit input[type=submit]").enable();
                });
        }
 });
index 70571b143c2db3e7417e8bdbb83c58a0a4c4bbd5..3521725280f549bac09ab3d4245b9b558f431cc5 100644 (file)
@@ -24,7 +24,7 @@ define(["require", "exports", "tslib", "./Status", "./Error", "../Core"], functi
         }
     }
     let ignoreConnectionErrors = false;
-    window.addEventListener("unload", () => (ignoreConnectionErrors = true));
+    window.addEventListener("beforeunload", () => (ignoreConnectionErrors = true));
     class BackendRequest {
         #url;
         #type;