Add offenders to imageOptimization
This commit is contained in:
@@ -865,7 +865,7 @@ var policies = {
|
||||
"imageOptimization": {
|
||||
"tool": "weightChecker",
|
||||
"label": "Image optimization",
|
||||
"message": "<p>This metric mesures the number of bytes that could be saved by optimizing images.</p><p>Image optimization is generally one of the easiest way to reduce a page weight, and as a result, the page load time. Don't use Photoshop or other image editing tools, they lie to you because they're generally not very good for optimization. Use specialized tools such as <a href=\"https://kraken.io/\" target=\"_blank\">Kraken.io</a> or the excellent <a href=\"https://imageoptim.com/\" target=\"_blank\">ImageOption</a> on Mac.</p><p>The tools in use in YellowLabTools are not set to their maximum optimization power, so you might be able to compress even more (the max JPEG quality is set to 85, which should be sufficient for any website).</p>",
|
||||
"message": "<p>This metric mesures the number of bytes that could be saved by optimizing images.</p><p>Image optimization is generally one of the easiest way to reduce a page weight, and as a result, the page load time. Don't use Photoshop or other image editing tools, they're not very good for optimization. Use specialized tools such as <a href=\"https://kraken.io/\" target=\"_blank\">Kraken.io</a> or the excellent <a href=\"https://imageoptim.com/\" target=\"_blank\">ImageOption</a> on Mac. For SVG images, you can use <a href=\"https://jakearchibald.github.io/svgomg/\" target=\"_blank\">SVGOMG</a></p><p>The tools in use in YellowLabTools are not set to their maximum optimization power, so you might be able to compress even more.</p>",
|
||||
"isOkThreshold": 30720,
|
||||
"isBadThreshold": 122880,
|
||||
"isAbnormalThreshold": 204800,
|
||||
|
||||
@@ -149,10 +149,12 @@ var ImageOptimizer = function() {
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// The gain is estimated of enough value if it's over 2KB or over 20%,
|
||||
// but it's ignored if is below 100 bytes
|
||||
function gainIsEnough(oldWeight, newWeight) {
|
||||
var gain = oldWeight - newWeight;
|
||||
var ratio = gain / oldWeight;
|
||||
return (gain > 2048 || ratio > 0.2);
|
||||
return (gain > 2048 || (ratio > 0.2 && gain > 100));
|
||||
}
|
||||
|
||||
function isJpeg(entry) {
|
||||
|
||||
@@ -140,45 +140,16 @@ var WeightChecker = function() {
|
||||
function listImageNotOptimized(requests) {
|
||||
var results = {
|
||||
totalGain: 0,
|
||||
byType: {
|
||||
jpeg: {
|
||||
totalGain: 0,
|
||||
requests: []
|
||||
},
|
||||
png: {
|
||||
totalGain: 0,
|
||||
requests: []
|
||||
},
|
||||
svg: {
|
||||
totalGain: 0,
|
||||
requests: []
|
||||
}
|
||||
}
|
||||
images: []
|
||||
};
|
||||
|
||||
requests.forEach(function(req) {
|
||||
var type = null;
|
||||
|
||||
switch(req.contentType) {
|
||||
case 'image/jpeg':
|
||||
type = 'jpeg';
|
||||
break;
|
||||
case 'image/png':
|
||||
type = 'png';
|
||||
break;
|
||||
case 'image/svg+xml':
|
||||
type = 'svg';
|
||||
break;
|
||||
}
|
||||
|
||||
if (type && req.weightCheck.bodySize && req.weightCheck.isOptimized === false) {
|
||||
if (req.weightCheck.bodySize && req.weightCheck.isOptimized === false) {
|
||||
var gain = req.weightCheck.bodySize - req.weightCheck.optimized;
|
||||
|
||||
results.totalGain += gain;
|
||||
|
||||
results.byType[type].totalGain += gain;
|
||||
|
||||
results.byType[type].requests.push({
|
||||
results.images.push({
|
||||
url: req.url,
|
||||
original: req.weightCheck.bodySize,
|
||||
optimized: req.weightCheck.optimized,
|
||||
|
||||
Reference in New Issue
Block a user