refactor: streamline image preloading logic in webpack config by defining critical images outside of conditional checks and improving preload count logging
This commit is contained in:
@@ -174,17 +174,18 @@ class InlineCssPlugin {
|
|||||||
htmlContent.includes('/admin') || htmlContent.includes('/404') ||
|
htmlContent.includes('/admin') || htmlContent.includes('/404') ||
|
||||||
htmlContent.includes('/widerrufsrecht') || htmlContent.includes('/batteriegesetzhinweise');
|
htmlContent.includes('/widerrufsrecht') || htmlContent.includes('/batteriegesetzhinweise');
|
||||||
|
|
||||||
|
// Define critical images array
|
||||||
|
const criticalImages = [
|
||||||
|
'/assets/images/filiale1.jpg',
|
||||||
|
'/assets/images/filiale2.jpg',
|
||||||
|
'/assets/images/seeds.jpg',
|
||||||
|
'/assets/images/cutlings.jpg',
|
||||||
|
'/assets/images/presse.jpg',
|
||||||
|
'/assets/images/purpl.jpg'
|
||||||
|
];
|
||||||
|
|
||||||
// Only preload navigation images for main pages (home, categories, aktionen, filiale)
|
// Only preload navigation images for main pages (home, categories, aktionen, filiale)
|
||||||
if (!isProductPage && !isSpecialPage) {
|
if (!isProductPage && !isSpecialPage) {
|
||||||
const criticalImages = [
|
|
||||||
'/assets/images/filiale1.jpg',
|
|
||||||
'/assets/images/filiale2.jpg',
|
|
||||||
'/assets/images/seeds.jpg',
|
|
||||||
'/assets/images/cutlings.jpg',
|
|
||||||
'/assets/images/presse.jpg',
|
|
||||||
'/assets/images/purpl.jpg'
|
|
||||||
];
|
|
||||||
|
|
||||||
criticalImages.forEach(imagePath => {
|
criticalImages.forEach(imagePath => {
|
||||||
imagePreloads += `<link rel="preload" href="${imagePath}" as="image">\n`;
|
imagePreloads += `<link rel="preload" href="${imagePath}" as="image">\n`;
|
||||||
});
|
});
|
||||||
@@ -198,8 +199,9 @@ class InlineCssPlugin {
|
|||||||
if (fontUrls.length > 0) {
|
if (fontUrls.length > 0) {
|
||||||
console.log(`✅ Added font preloads: ${fontUrls.length} fonts`);
|
console.log(`✅ Added font preloads: ${fontUrls.length} fonts`);
|
||||||
}
|
}
|
||||||
if (criticalImages.length > 0) {
|
if (imagePreloads.length > 0) {
|
||||||
console.log(`✅ Added image preloads: ${criticalImages.length} critical images`);
|
const preloadCount = (imagePreloads.match(/<link/g) || []).length;
|
||||||
|
console.log(`✅ Added image preloads: ${preloadCount} critical images`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user