Add offenders to imageOptimization
This commit is contained in:
@@ -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