Skip to content

Commit

Permalink
core(config): enable unused-javascript by default (#9854)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed Nov 6, 2019
1 parent 466bd6f commit 713a70a
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 23 deletions.
11 changes: 11 additions & 0 deletions lighthouse-cli/test/cli/__snapshots__/index-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ Object {
Object {
"path": "byte-efficiency/unused-css-rules",
},
Object {
"path": "byte-efficiency/unused-javascript",
},
Object {
"path": "byte-efficiency/uses-webp-images",
},
Expand Down Expand Up @@ -799,6 +802,11 @@ Object {
"id": "unused-css-rules",
"weight": 0,
},
Object {
"group": "load-opportunities",
"id": "unused-javascript",
"weight": 0,
},
Object {
"group": "load-opportunities",
"id": "uses-optimized-images",
Expand Down Expand Up @@ -1169,6 +1177,9 @@ Object {
Object {
"path": "css-usage",
},
Object {
"path": "js-usage",
},
Object {
"path": "viewport-dimensions",
},
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/audits/byte-efficiency/unused-javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const UIStrings = {
/** Imperative title of a Lighthouse audit that tells the user to remove JavaScript that is never evaluated during page load. This is displayed in a list of audit titles that Lighthouse generates. */
title: 'Remove unused JavaScript',
/** Description of a Lighthouse audit that tells the user *why* they should remove JavaScript that is never needed/evaluated by the browser. This is displayed after a user expands the section to see more. No character length limits. 'Learn More' becomes link text to additional documentation. */
description: 'Remove unused JavaScript to reduce bytes consumed by network activity.',
description: 'Remove unused JavaScript to reduce bytes consumed by network activity. ' +
'[Learn more](https://developers.google.com/web/fundamentals/performance/optimizing-javascript/code-splitting).',
};

const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
Expand Down
3 changes: 3 additions & 0 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const defaultConfig = {
cpuQuietThresholdMs: 1000,
gatherers: [
'css-usage',
'js-usage',
'viewport-dimensions',
'runtime-exceptions',
'console-messages',
Expand Down Expand Up @@ -275,6 +276,7 @@ const defaultConfig = {
'byte-efficiency/unminified-css',
'byte-efficiency/unminified-javascript',
'byte-efficiency/unused-css-rules',
'byte-efficiency/unused-javascript',
'byte-efficiency/uses-webp-images',
'byte-efficiency/uses-optimized-images',
'byte-efficiency/uses-text-compression',
Expand Down Expand Up @@ -393,6 +395,7 @@ const defaultConfig = {
{id: 'unminified-css', weight: 0, group: 'load-opportunities'},
{id: 'unminified-javascript', weight: 0, group: 'load-opportunities'},
{id: 'unused-css-rules', weight: 0, group: 'load-opportunities'},
{id: 'unused-javascript', weight: 0, group: 'load-opportunities'},
{id: 'uses-optimized-images', weight: 0, group: 'load-opportunities'},
{id: 'uses-webp-images', weight: 0, group: 'load-opportunities'},
{id: 'uses-text-compression', weight: 0, group: 'load-opportunities'},
Expand Down
19 changes: 0 additions & 19 deletions lighthouse-core/config/full-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,6 @@
const fullConfig = {
extends: 'lighthouse:default',
settings: {},
passes: [
{
passName: 'extraPass',
gatherers: [
'js-usage',
],
},
],
audits: [
'byte-efficiency/unused-javascript',
],
// @ts-ignore TODO(bckenny): type extended Config where e.g. category.title isn't required
categories: {
'performance': {
auditRefs: [
{id: 'unused-javascript', weight: 0, group: 'load-opportunities'},
],
},
},
};

module.exports = fullConfig;
2 changes: 1 addition & 1 deletion lighthouse-core/gather/gatherers/js-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class JsUsage extends Gatherer {
*/
async beforePass(passContext) {
await passContext.driver.sendCommand('Profiler.enable');
await passContext.driver.sendCommand('Profiler.startPreciseCoverage');
await passContext.driver.sendCommand('Profiler.startPreciseCoverage', {detailed: false});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/i18n/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
"message": "Remove unused CSS"
},
"lighthouse-core/audits/byte-efficiency/unused-javascript.js | description": {
"message": "Remove unused JavaScript to reduce bytes consumed by network activity."
"message": "Remove unused JavaScript to reduce bytes consumed by network activity. [Learn more](https://developers.google.com/web/fundamentals/performance/optimizing-javascript/code-splitting)."
},
"lighthouse-core/audits/byte-efficiency/unused-javascript.js | title": {
"message": "Remove unused JavaScript"
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/lib/i18n/locales/en-XL.json
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
"message": "R̂ém̂óv̂é ûńûśêd́ ĈŚŜ"
},
"lighthouse-core/audits/byte-efficiency/unused-javascript.js | description": {
"message": "R̂ém̂óv̂é ûńûśêd́ Ĵáv̂áŜćr̂íp̂t́ t̂ó r̂éd̂úĉé b̂ýt̂éŝ ćôńŝúm̂éd̂ b́ŷ ńêt́ŵór̂ḱ âćt̂ív̂ít̂ý."
"message": "R̂ém̂óv̂é ûńûśêd́ Ĵáv̂áŜćr̂íp̂t́ t̂ó r̂éd̂úĉé b̂ýt̂éŝ ćôńŝúm̂éd̂ b́ŷ ńêt́ŵór̂ḱ âćt̂ív̂ít̂ý. [L̂éâŕn̂ ḿôŕê](https://developers.google.com/web/fundamentals/performance/optimizing-javascript/code-splitting)."
},
"lighthouse-core/audits/byte-efficiency/unused-javascript.js | title": {
"message": "R̂ém̂óv̂é ûńûśêd́ Ĵáv̂áŜćr̂íp̂t́"
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/test/results/artifacts/artifacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
"requestId": "75994.22"
}
],
"JsUsage": [],
"CSSUsage": {
"rules": [
{
Expand Down
33 changes: 33 additions & 0 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,22 @@
"overallSavingsBytes": 0
}
},
"unused-javascript": {
"id": "unused-javascript",
"title": "Remove unused JavaScript",
"description": "Remove unused JavaScript to reduce bytes consumed by network activity. [Learn more](https://developers.google.com/web/fundamentals/performance/optimizing-javascript/code-splitting).",
"score": 1,
"scoreDisplayMode": "numeric",
"numericValue": 0,
"displayValue": "",
"details": {
"type": "opportunity",
"headings": [],
"items": [],
"overallSavingsMs": 0,
"overallSavingsBytes": 0
}
},
"uses-webp-images": {
"id": "uses-webp-images",
"title": "Serve images in next-gen formats",
Expand Down Expand Up @@ -3532,6 +3548,11 @@
"weight": 0,
"group": "load-opportunities"
},
{
"id": "unused-javascript",
"weight": 0,
"group": "load-opportunities"
},
{
"id": "uses-optimized-images",
"weight": 0,
Expand Down Expand Up @@ -5078,6 +5099,12 @@
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:unused-javascript",
"duration": 100,
"entryType": "measure"
},
{
"startTime": 0,
"name": "lh:audit:uses-webp-images",
Expand Down Expand Up @@ -6158,6 +6185,12 @@
"lighthouse-core/audits/byte-efficiency/unused-css-rules.js | description": [
"audits[unused-css-rules].description"
],
"lighthouse-core/audits/byte-efficiency/unused-javascript.js | title": [
"audits[unused-javascript].title"
],
"lighthouse-core/audits/byte-efficiency/unused-javascript.js | description": [
"audits[unused-javascript].description"
],
"lighthouse-core/audits/byte-efficiency/uses-webp-images.js | title": [
"audits[uses-webp-images].title"
],
Expand Down
26 changes: 26 additions & 0 deletions proto/sample_v2_round_trip.json
Original file line number Diff line number Diff line change
Expand Up @@ -2851,6 +2851,21 @@
"scoreDisplayMode": "numeric",
"title": "Remove unused CSS"
},
"unused-javascript": {
"description": "Remove unused JavaScript to reduce bytes consumed by network activity. [Learn more](https://developers.google.com/web/fundamentals/performance/optimizing-javascript/code-splitting).",
"details": {
"headings": [],
"items": [],
"overallSavingsBytes": 0.0,
"overallSavingsMs": 0.0,
"type": "opportunity"
},
"id": "unused-javascript",
"numericValue": 0.0,
"score": 1.0,
"scoreDisplayMode": "numeric",
"title": "Remove unused JavaScript"
},
"use-landmarks": {
"description": "Landmark elements (<main>, <nav>, etc.) are used to improve the keyboard navigation of the page for assistive technology. [Learn more](https://web.dev/use-landmarks/).",
"id": "use-landmarks",
Expand Down Expand Up @@ -3696,6 +3711,11 @@
"id": "unused-css-rules",
"weight": 0.0
},
{
"group": "load-opportunities",
"id": "unused-javascript",
"weight": 0.0
},
{
"group": "load-opportunities",
"id": "uses-optimized-images",
Expand Down Expand Up @@ -4979,6 +4999,12 @@
"name": "lh:audit:unused-css-rules",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
"name": "lh:audit:unused-javascript",
"startTime": 0.0
},
{
"duration": 100.0,
"entryType": "measure",
Expand Down

0 comments on commit 713a70a

Please sign in to comment.