|
@@ -340,9 +340,34 @@ var Redownload = function() {
|
|
|
};
|
|
|
|
|
|
requests.forEach(function(req) {
|
|
|
+
|
|
|
if (req.weightCheck.bodySize > 0 && imageOptimizer.entryTypeCanBeOptimized(req) && req.weightCheck.isOptimized === false) {
|
|
|
- var before = req.weightCheck.afterGzipCompression || req.weightCheck.bodySize;
|
|
|
- var after = req.weightCheck.afterOptimizationAndGzipCompression || req.weightCheck.optimized;
|
|
|
+
|
|
|
+ var before, after;
|
|
|
+
|
|
|
+ if (req.weightCheck.isCompressed === true) {
|
|
|
+ // The resource is compressed
|
|
|
+
|
|
|
+ before = req.weightCheck.bodySize;
|
|
|
+
|
|
|
+ if (req.weightCheck.compressionTool === 'brotli') {
|
|
|
+ after = req.weightCheck.afterOptimizationAndBrotliCompression;
|
|
|
+ } else {
|
|
|
+ after = req.weightCheck.afterOptimizationAndGzipCompression;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (req.weightCheck.afterBrotliCompression) {
|
|
|
+ // The resource is not compressed but should be
|
|
|
+
|
|
|
+ before = req.weightCheck.afterBrotliCompression;
|
|
|
+ after = req.weightCheck.afterOptimizationAndBrotliCompression;
|
|
|
+ } else {
|
|
|
+ // The resource is not compressed but is not subject to compression
|
|
|
+
|
|
|
+ before = req.weightCheck.bodySize;
|
|
|
+ after = req.weightCheck.optimized;
|
|
|
+ }
|
|
|
+
|
|
|
var gain = before - after;
|
|
|
|
|
|
if (gain > 200) {
|
|
@@ -350,10 +375,11 @@ var Redownload = function() {
|
|
|
|
|
|
results.images.push({
|
|
|
url: req.url,
|
|
|
- original: req.weightCheck.bodySize,
|
|
|
+ originalWeigth: req.weightCheck.bodySize,
|
|
|
+ isCompressible: (req.weightCheck.afterBrotliCompression > 0),
|
|
|
isCompressed: req.weightCheck.isCompressed,
|
|
|
- afterGzipCompression: req.weightCheck.afterGzipCompression,
|
|
|
- afterOptimizationAndGzipCompression: req.weightCheck.afterOptimizationAndGzipCompression,
|
|
|
+ originalCompressedWeight: before,
|
|
|
+ afterOptimizationAndCompression: after,
|
|
|
lossless: req.weightCheck.lossless,
|
|
|
lossy: req.weightCheck.lossy,
|
|
|
gain: gain
|
|
@@ -361,7 +387,6 @@ var Redownload = function() {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
-
|
|
|
return results;
|
|
|
}
|
|
|
|
|
@@ -405,15 +430,43 @@ var Redownload = function() {
|
|
|
var after = req.weightCheck.afterOptimizationAndGzipCompression || req.weightCheck.optimized;
|
|
|
var gain = before - after;
|
|
|
|
|
|
+ var before, after;
|
|
|
+
|
|
|
+ if (req.weightCheck.isCompressed === true) {
|
|
|
+ // The resource is compressed
|
|
|
+
|
|
|
+ before = req.weightCheck.bodySize;
|
|
|
+
|
|
|
+ if (req.weightCheck.compressionTool === 'brotli') {
|
|
|
+ after = req.weightCheck.afterOptimizationAndBrotliCompression;
|
|
|
+ } else {
|
|
|
+ after = req.weightCheck.afterOptimizationAndGzipCompression;
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (req.weightCheck.afterBrotliCompression) {
|
|
|
+ // The resource is not compressed but should be
|
|
|
+
|
|
|
+ before = req.weightCheck.afterBrotliCompression;
|
|
|
+ after = req.weightCheck.afterOptimizationAndBrotliCompression;
|
|
|
+ } else {
|
|
|
+ // The resource is not compressed but is not subject to compression
|
|
|
+
|
|
|
+ before = req.weightCheck.bodySize;
|
|
|
+ after = req.weightCheck.optimized;
|
|
|
+ }
|
|
|
+
|
|
|
+ var gain = before - after;
|
|
|
+
|
|
|
if (gain > 200) {
|
|
|
results.totalGain += gain;
|
|
|
|
|
|
results.files.push({
|
|
|
url: req.url,
|
|
|
- original: req.weightCheck.bodySize,
|
|
|
+ originalWeigth: req.weightCheck.bodySize,
|
|
|
+ isCompressible: (req.weightCheck.afterBrotliCompression > 0),
|
|
|
isCompressed: req.weightCheck.isCompressed,
|
|
|
- afterGzipCompression: req.weightCheck.afterGzipCompression,
|
|
|
- afterOptimizationAndGzipCompression: req.weightCheck.afterOptimizationAndGzipCompression,
|
|
|
+ originalCompressedWeight: before,
|
|
|
+ afterOptimizationAndCompression: after,
|
|
|
optimized: req.weightCheck.optimized,
|
|
|
gain: gain
|
|
|
});
|