From 6a6c62ada25f90dfc7141835bbaaa9831ec36f3c Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Mon, 30 Jan 2017 10:01:52 -0800 Subject: [PATCH] fix(optimized-images): dedupe image URLs --- .../gather/gatherers/dobetterweb/optimized-images.js | 6 ++++++ .../gather/gatherers/dobetterweb/optimized-images-test.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js index 52d029625b8e..b06a548519ea 100644 --- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js +++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js @@ -71,7 +71,13 @@ class OptimizedImages extends Gatherer { * @return {!Array<{url: string, isBase64DataUri: boolean, mimeType: string, resourceSize: number}>} */ static filterImageRequests(pageUrl, networkRecords) { + const seenUrls = new Set(); return networkRecords.reduce((prev, record) => { + if (seenUrls.has(record._url)) { + return prev; + } + + seenUrls.add(record._url); const isOptimizableImage = /image\/(png|bmp|jpeg)/.test(record._mimeType); const isSameOrigin = URL.hostsMatch(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 996924a19e88..8473686bcaaa 100644 --- a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js +++ b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js @@ -44,6 +44,11 @@ const traceData = { _mimeType: 'image/bmp', _resourceSize: 12, }, + { + _url: 'http://google.com/image.bmp', + _mimeType: 'image/bmp', + _resourceSize: 12, + }, { _url: 'http://google.com/vector.svg', _mimeType: 'image/svg+xml',