From c906e0c936e70f9a14ce72071d95e43c4ce6679e Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Wed, 23 Jul 2025 08:52:53 +0200 Subject: [PATCH] refactor: enhance image preloading logic in InlineCssPlugin for better performance and clarity --- src/services/SocketManager.js | 6 +----- webpack.config.js | 25 ++++++++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/services/SocketManager.js b/src/services/SocketManager.js index 70ad7fb..9b2fbe1 100644 --- a/src/services/SocketManager.js +++ b/src/services/SocketManager.js @@ -28,17 +28,13 @@ class SocketManager { } this.pendingListeners.get(event).add(callback); - // If not already connecting, initiate connection - if (!this.connectPromise) { - this.connect(); - } - // Register the listener now, it will receive events once connected this.socket.on(event, callback); } off(event, callback) { // Remove from socket listeners + console.log('off', event, callback); this.socket.off(event, callback); // Remove from pending listeners if present diff --git a/webpack.config.js b/webpack.config.js index 9b1e71d..4ed99f1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -168,13 +168,19 @@ class InlineCssPlugin { // Extract current page path from the HTML to determine which images to preload const htmlContent = data.html; - const isProductPage = htmlContent.includes('/Artikel/') || htmlContent.includes('product-detail'); - const isSpecialPage = htmlContent.includes('/impressum') || htmlContent.includes('/datenschutz') || - htmlContent.includes('/agb') || htmlContent.includes('/profile') || - htmlContent.includes('/admin') || htmlContent.includes('/404') || - htmlContent.includes('/widerrufsrecht') || htmlContent.includes('/batteriegesetzhinweise'); + const isProductPage = htmlContent.includes('ProductDetailPage') || + htmlContent.includes('/Artikel/') || + htmlContent.includes('product-detail'); + const isSpecialPage = htmlContent.includes('/impressum') || + htmlContent.includes('/datenschutz') || + htmlContent.includes('/agb') || + htmlContent.includes('/profile') || + htmlContent.includes('/admin') || + htmlContent.includes('/404') || + htmlContent.includes('/widerrufsrecht') || + htmlContent.includes('/batteriegesetzhinweise'); - // Define critical images array + // Define critical images array - only preload these on pages that actually use them const criticalImages = [ '/assets/images/filiale1.jpg', '/assets/images/filiale2.jpg', @@ -186,9 +192,10 @@ class InlineCssPlugin { // Only preload navigation images for main pages (home, categories, aktionen, filiale) if (!isProductPage && !isSpecialPage) { - criticalImages.forEach(imagePath => { - imagePreloads += `\n`; - }); + // Add the as="image" attribute to ensure proper preloading + criticalImages.forEach(imagePath => { + imagePreloads += `\n`; + }); } // Add inlined CSS to head