Skip to content

Commit eb76d9d

Browse files
Adam RaineDevtools-frontend LUCI CQ
authored andcommitted
[ImageDelivery] Decompose messages so est savings can be discarded in LH
Bug: 388723721 Change-Id: I690dc3e25019a0c12e617d301fd4569969c0c79d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6249602 Reviewed-by: Connor Clark <[email protected]> Commit-Queue: Adam Raine <[email protected]>
1 parent 0c69d8a commit eb76d9d

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

front_end/models/trace/insights/ImageDelivery.ts

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,24 @@ export const UIStrings = {
2727
'Reducing the download time of images can improve the perceived load time of the page and LCP. [Learn more about optimizing image size](https://developer.chrome.com/docs/lighthouse/performance/uses-optimized-images/)',
2828
/**
2929
* @description Message displayed in a chip explaining that an image file size is large for the # of pixels it has and recommends possible adjustments to improve the image size.
30-
* @example {50 MB} PH1
3130
*/
32-
useCompression: 'Increasing the image compression factor could improve this image\'s download size. (Est {PH1})',
31+
useCompression: 'Increasing the image compression factor could improve this image\'s download size.',
3332
/**
3433
* @description Message displayed in a chip explaining that an image file size is large for the # of pixels it has and recommends possible adjustments to improve the image size.
35-
* @example {50 MB} PH1
3634
*/
3735
useModernFormat:
38-
'Using a modern image format (WebP, AVIF) or increasing the image compression could improve this image\'s download size. (Est {PH1})',
36+
'Using a modern image format (WebP, AVIF) or increasing the image compression could improve this image\'s download size.',
3937
/**
4038
* @description Message displayed in a chip advising the user to use video formats instead of GIFs because videos generally have smaller file sizes.
41-
* @example {50 MB} PH1
4239
*/
43-
useVideoFormat: 'Using video formats instead of GIFs can improve the download size of animated content. (Est {PH1})',
40+
useVideoFormat: 'Using video formats instead of GIFs can improve the download size of animated content.',
4441
/**
4542
* @description Message displayed in a chip explaining that an image was displayed on the page with dimensions much smaller than the image file dimensions.
46-
* @example {50 MB} PH1
47-
* @example {1000x500} PH2
48-
* @example {100x50} PH3
43+
* @example {1000x500} PH1
44+
* @example {100x50} PH2
4945
*/
5046
useResponsiveSize:
51-
'This image file is larger than it needs to be ({PH2}) for its displayed dimensions ({PH3}). Use responsive images to reduce the image download size. (Est {PH1})',
47+
'This image file is larger than it needs to be ({PH1}) for its displayed dimensions ({PH2}). Use responsive images to reduce the image download size.',
5248
/**
5349
* @description Column header for a table column containing network requests for images which can improve their file size (e.g. use a different format, increase compression, etc).
5450
*/
@@ -62,6 +58,12 @@ export const UIStrings = {
6258
* @description Text status indicating that no potential optimizations were found for any image file
6359
*/
6460
noOptimizableImages: 'No optimizable images',
61+
/**
62+
* @description Text describing the estimated number of bytes that an image file optimization can save. This text is appended to another block of text describing the image optimization in more detail. "Est" means "Estimated".
63+
* @example {Use the correct image dimensions to reduce the image file size.} PH1
64+
* @example {50 MB} PH2
65+
*/
66+
estimatedSavings: '{PH1} (Est {PH2})',
6567
};
6668

6769
const str_ = i18n.i18n.registerUIStrings('models/trace/insights/ImageDelivery.ts', UIStrings);
@@ -132,24 +134,28 @@ export type ImageDeliveryInsightModel = InsightModel<typeof UIStrings, {
132134
totalByteSavings: number,
133135
}>;
134136

135-
function getOptimizationMessage(optimization: ImageOptimization): string {
136-
const byteSavingsText = i18n.ByteUtilities.bytesToString(optimization.byteSavings);
137+
export function getOptimizationMessage(optimization: ImageOptimization): string {
137138
switch (optimization.type) {
138139
case ImageOptimizationType.ADJUST_COMPRESSION:
139-
return i18nString(UIStrings.useCompression, {PH1: byteSavingsText});
140+
return i18nString(UIStrings.useCompression);
140141
case ImageOptimizationType.MODERN_FORMAT_OR_COMPRESSION:
141-
return i18nString(UIStrings.useModernFormat, {PH1: byteSavingsText});
142+
return i18nString(UIStrings.useModernFormat);
142143
case ImageOptimizationType.VIDEO_FORMAT:
143-
return i18nString(UIStrings.useVideoFormat, {PH1: byteSavingsText});
144+
return i18nString(UIStrings.useVideoFormat);
144145
case ImageOptimizationType.RESPONSIVE_SIZE:
145146
return i18nString(UIStrings.useResponsiveSize, {
146-
PH1: byteSavingsText,
147-
PH2: `${optimization.fileDimensions.width}x${optimization.fileDimensions.height}`,
148-
PH3: `${optimization.displayDimensions.width}x${optimization.displayDimensions.height}`,
147+
PH1: `${optimization.fileDimensions.width}x${optimization.fileDimensions.height}`,
148+
PH2: `${optimization.displayDimensions.width}x${optimization.displayDimensions.height}`,
149149
});
150150
}
151151
}
152152

153+
export function getOptimizationMessageWithBytes(optimization: ImageOptimization): string {
154+
const byteSavingsText = i18n.ByteUtilities.bytesToString(optimization.byteSavings);
155+
const optimizationMessage = getOptimizationMessage(optimization);
156+
return i18nString(UIStrings.estimatedSavings, {PH1: optimizationMessage, PH2: byteSavingsText});
157+
}
158+
153159
function finalize(partialModel: PartialInsightModel<ImageDeliveryInsightModel>): ImageDeliveryInsightModel {
154160
return {
155161
strings: UIStrings,
@@ -158,8 +164,8 @@ function finalize(partialModel: PartialInsightModel<ImageDeliveryInsightModel>):
158164
category: InsightCategory.LCP,
159165
state: partialModel.optimizableImages.length > 0 ? 'fail' : 'pass',
160166
...partialModel,
161-
relatedEvents: new Map(
162-
partialModel.optimizableImages.map(image => [image.request, image.optimizations.map(getOptimizationMessage)])),
167+
relatedEvents: new Map(partialModel.optimizableImages.map(
168+
image => [image.request, image.optimizations.map(getOptimizationMessageWithBytes)])),
163169
};
164170
}
165171

0 commit comments

Comments
 (0)