Add offenders to imageOptimization

This commit is contained in:
Gaël Métais
2015-06-01 16:52:50 +02:00
parent 1606cbab18
commit 9ccca3b33b
9 changed files with 85 additions and 47 deletions
+3 -1
View File
@@ -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) {
+3 -32
View File
@@ -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,