From a6539086245a313c7e61771694fda8e7c163d235 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Wed, 23 Jul 2025 09:10:45 +0200 Subject: [PATCH] refactor: simplify image preloading logic in InlineCssPlugin to focus on homepage and enhance console logging --- webpack.config.js | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 67a3f22..f0ba916 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -166,35 +166,25 @@ class InlineCssPlugin { // Skip preloading on product detail pages and other specific pages let imagePreloads = ''; - // Extract current page path from the HTML to determine which images to preload // Get the output filename to determine page type const outputPath = data.outputName || ''; - // Simple path-based detection - const isProductPage = outputPath.includes('Artikel/'); - const isSpecialPage = outputPath.includes('impressum') || - outputPath.includes('datenschutz') || - outputPath.includes('agb') || - outputPath.includes('profile') || - outputPath.includes('admin') || - outputPath.includes('404') || - outputPath.includes('widerrufsrecht') || - outputPath.includes('batteriegesetzhinweise'); + // Only preload on homepage - check if this is the main index.html + const isHomePage = outputPath === 'index.html'; - // Define critical images array - only preload these on pages that actually use them + // Define critical images array - only preload these on homepage const criticalImages = [ - /*'/assets/images/filiale1.jpg', + '/assets/images/filiale1.jpg', '/assets/images/filiale2.jpg', '/assets/images/seeds.jpg', '/assets/images/cutlings.jpg', '/assets/images/presse.jpg', - '/assets/images/purpl.jpg'*/ + '/assets/images/purpl.jpg' ]; - // Only preload navigation images for main pages (home, categories, aktionen, filiale) - // NEVER preload on product pages + // Only preload navigation images for homepage let preloadCount = 0; - if (!isProductPage && !isSpecialPage) { + if (isHomePage) { // Add the as="image" attribute to ensure proper preloading criticalImages.forEach(imagePath => { imagePreloads += `\n`; @@ -211,8 +201,8 @@ class InlineCssPlugin { console.log(`✅ Added font preloads: ${fontUrls.length} fonts`); } - // Log whether this is a product page and if images were preloaded - console.log(`Page type: ${isProductPage ? 'Product Page' : isSpecialPage ? 'Special Page' : 'Regular Page'} (${outputPath})`); + // Log whether images were preloaded + console.log(`Page: ${outputPath} - Is homepage: ${isHomePage}`); if (preloadCount > 0) { console.log(`✅ Added image preloads: ${preloadCount} critical images`);