Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(optimized-images): support non-standard mime types #5688

Merged
merged 1 commit into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const WEBP_QUALITY = 0.85;

const MINIMUM_IMAGE_SIZE = 4096; // savings of <4 KB will be ignored in the audit anyway

const IMAGE_REGEX = /^image\/((x|ms|x-ms)-)?(png|bmp|jpeg)$/;

/** @typedef {{isSameOrigin: boolean, isBase64DataUri: boolean, requestId: string, url: string, mimeType: string, resourceSize: number}} SimplifiedNetworkRecord */

/* global document, Image, atob */
Expand Down Expand Up @@ -87,7 +89,7 @@ class OptimizedImages extends Gatherer {

seenUrls.add(record.url);
const isOptimizableImage = record.resourceType === NetworkRequest.TYPES.Image &&
/image\/(png|bmp|jpeg)/.test(record.mimeType);
IMAGE_REGEX.test(record.mimeType);
const isSameOrigin = URL.originsMatch(pageUrl, record.url);
const isBase64DataUri = /^data:.{2,40}base64\s*,/.test(record.url);

Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/audits/dobetterweb/doctype-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const Audit = require('../../../audits/dobetterweb/doctype.js');
const assert = require('assert');

/* eslint-env mocha */
/* eslint-env jest */

describe('DOBETTERWEB: doctype audit', () => {
it('fails when document does not contain a doctype', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

/* eslint-env mocha */
/* eslint-env jest */

const OptimizedImages =
require('../../../../gather/gatherers/dobetterweb/optimized-images');
Expand Down Expand Up @@ -185,4 +185,23 @@ describe('Optimized images', () => {
assert.ok(/gmail.*image.jpg/.test(artifact[3].url));
});
});

it('handles non-standard mime types too', async () => {
const traceData = {
networkRecords: [
{
requestId: '1',
url: 'http://google.com/image.bmp?x-ms',
mimeType: 'image/x-ms-bmp',
resourceSize: 12000,
transferSize: 20000,
resourceType: 'Image',
finished: true,
},
],
};

const artifact = await optimizedImages.afterPass(options, traceData);
expect(artifact).toHaveLength(1);
});
});