|
@@ -421,20 +421,46 @@ var Redownload = function() {
|
|
|
|
|
|
var image = {
|
|
var image = {
|
|
url: req.url,
|
|
url: req.url,
|
|
- originalWeigth: req.weightCheck.bodySize
|
|
|
|
|
|
+ originalWeigth: req.weightCheck.bodySize,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ switch (req.contentType) {
|
|
|
|
+ case 'image/jpeg':
|
|
|
|
+ image.originalFormat = 'JPEG';
|
|
|
|
+ break;
|
|
|
|
+ case 'image/png':
|
|
|
|
+ image.originalFormat = 'PNG';
|
|
|
|
+ break;
|
|
|
|
+ case 'image/gif':
|
|
|
|
+ image.originalFormat = 'GIF';
|
|
|
|
+ break;
|
|
|
|
+ case 'image/webp':
|
|
|
|
+ image.originalFormat = 'WebP';
|
|
|
|
+ break;
|
|
|
|
+ case 'image/avif':
|
|
|
|
+ image.originalFormat = 'AVIF';
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (req.weightCheck.webpSize) {
|
|
if (req.weightCheck.webpSize) {
|
|
image.webpSize = req.weightCheck.webpSize;
|
|
image.webpSize = req.weightCheck.webpSize;
|
|
|
|
+ image.webpGain = req.weightCheck.bodySize - req.weightCheck.webpSize;
|
|
|
|
+
|
|
|
|
+ image.bestFormat = 'WebP';
|
|
|
|
+ image.maxGain = image.webpGain;
|
|
}
|
|
}
|
|
|
|
+
|
|
if (req.weightCheck.avifSize) {
|
|
if (req.weightCheck.avifSize) {
|
|
image.avifSize = req.weightCheck.avifSize;
|
|
image.avifSize = req.weightCheck.avifSize;
|
|
- }
|
|
|
|
|
|
+ image.avifGain = req.weightCheck.bodySize - req.weightCheck.avifSize;
|
|
|
|
|
|
- var smallest = Math.min(image.webpSize || Infinity, image.avifSize || Infinity);
|
|
|
|
- image.gain = req.weightCheck.bodySize - smallest;
|
|
|
|
|
|
+ if (!req.weightCheck.webpSize || req.weightCheck.webpSize > req.weightCheck.avifSize) {
|
|
|
|
+ image.bestFormat = 'AVIF';
|
|
|
|
+ image.maxGain = image.avifGain;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- results.totalGain += image.gain;
|
|
|
|
|
|
+ results.totalGain += image.maxGain;
|
|
results.images.push(image);
|
|
results.images.push(image);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
@@ -863,9 +889,9 @@ var Redownload = function() {
|
|
|
|
|
|
debug('Downloading %s', entry.url);
|
|
debug('Downloading %s', entry.url);
|
|
|
|
|
|
- // Always add compression and webp headers before sending, in case the server listens to them
|
|
|
|
|
|
+ // Always add compression and webp/avif headers before sending, in case the server listens to them
|
|
var reqHeaders = [];
|
|
var reqHeaders = [];
|
|
- reqHeaders['Accept'] = '*/*,image/webp';
|
|
|
|
|
|
+ reqHeaders['Accept'] = '*/*,image/webp,image/avif';
|
|
reqHeaders['Accept-Encoding'] = 'gzip, deflate, br';
|
|
reqHeaders['Accept-Encoding'] = 'gzip, deflate, br';
|
|
reqHeaders['Connection'] = 'keep-alive';
|
|
reqHeaders['Connection'] = 'keep-alive';
|
|
reqHeaders['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36';
|
|
reqHeaders['User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36';
|