From 3d0b9ee97d44d8db4bc1e9298be0d6574ac49523 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 13 Dec 2017 11:02:20 -0800 Subject: [PATCH] core(optimized-images): skip mismatched mimeTypes --- .../gatherers/dobetterweb/optimized-images.js | 4 +++- .../dobetterweb/optimized-images-test.js | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index aebc1ac0ad20..4b70729675c8 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js @@ -73,7 +73,9 @@ class OptimizedImages extends Gatherer { } seenUrls.add(record._url); - const isOptimizableImage = /image\/(png|bmp|jpeg)/.test(record._mimeType); + const isOptimizableImage = record._resourceType && + record._resourceType._name === 'image' && + /image\/(png|bmp|jpeg)/.test(record._mimeType); const isSameOrigin = URL.originsMatch(pageUrl, record._url); const isBase64DataUri = /^data:.{2,40}base64\s*,/.test(record._url); diff --git a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js index dba919408512..a725331c95be 100644 --- a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js +++ b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js @@ -23,50 +23,65 @@ const traceData = { _url: 'http://google.com/image.jpg', _mimeType: 'image/jpeg', _resourceSize: 10000, + _resourceType: {_name: 'image'}, finished: true, }, { _url: 'http://google.com/transparent.png', _mimeType: 'image/png', _resourceSize: 11000, + _resourceType: {_name: 'image'}, finished: true, }, { _url: 'http://google.com/image.bmp', _mimeType: 'image/bmp', _resourceSize: 12000, + _resourceType: {_name: 'image'}, finished: true, }, { _url: 'http://google.com/image.bmp', _mimeType: 'image/bmp', _resourceSize: 12000, + _resourceType: {_name: 'image'}, finished: true, }, { _url: 'http://google.com/vector.svg', _mimeType: 'image/svg+xml', _resourceSize: 13000, + _resourceType: {_name: 'image'}, finished: true, }, { _url: 'http://gmail.com/image.jpg', _mimeType: 'image/jpeg', _resourceSize: 15000, + _resourceType: {_name: 'image'}, finished: true, }, { _url: 'data: image/jpeg ; base64 ,SgVcAT32587935321...', _mimeType: 'image/jpeg', + _resourceType: {_name: 'image'}, _resourceSize: 14000, finished: true, }, { _url: 'http://google.com/big-image.bmp', _mimeType: 'image/bmp', + _resourceType: {_name: 'image'}, _resourceSize: 12000, finished: false, // ignore for not finishing }, + { + _url: 'http://google.com/not-an-image.bmp', + _mimeType: 'image/bmp', + _resourceType: {_name: 'document'}, // ignore for not really being an image + _resourceSize: 12000, + finished: true, + }, ], };