lighthouse 12.8.2-dev.20251005 → 12.8.2-dev.20251007
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/test/smokehouse/config/exclusions.js +0 -2
- package/core/audits/audit.js +0 -1
- package/core/audits/insights/cls-culprits-insight.js +1 -1
- package/core/audits/insights/dom-size-insight.js +11 -7
- package/core/audits/insights/insight-audit.d.ts +4 -2
- package/core/audits/insights/insight-audit.js +22 -3
- package/core/audits/predictive-perf.js +2 -2
- package/core/audits/seo/crawlable-anchors.js +2 -3
- package/core/audits/server-response-time.d.ts +0 -5
- package/core/audits/server-response-time.js +12 -26
- package/core/computed/metrics/lcp-breakdown.d.ts +10 -5
- package/core/computed/metrics/lcp-breakdown.js +50 -22
- package/core/computed/metrics/time-to-first-byte.js +33 -10
- package/core/computed/metrics/timing-summary.js +3 -2
- package/core/config/default-config.js +20 -63
- package/core/config/experimental-config.js +1 -26
- package/core/config/filters.js +6 -9
- package/core/config/lr-desktop-config.js +0 -1
- package/core/config/lr-mobile-config.js +0 -1
- package/core/gather/gatherers/anchor-elements.js +8 -24
- package/core/gather/gatherers/inspector-issues.js +1 -28
- package/core/gather/gatherers/trace-elements.d.ts +0 -9
- package/core/gather/gatherers/trace-elements.js +0 -35
- package/core/lib/network-request.d.ts +0 -7
- package/core/lib/network-request.js +0 -16
- package/core/lib/proto-preprocessor.js +5 -22
- package/dist/report/bundle.esm.js +10 -49
- package/dist/report/flow.js +12 -51
- package/dist/report/standalone.js +11 -50
- package/flow-report/src/i18n/i18n.d.ts +4 -6
- package/package.json +4 -5
- package/report/assets/styles.css +0 -39
- package/report/renderer/api.js +0 -1
- package/report/renderer/category-renderer.js +6 -0
- package/report/renderer/components.js +1 -1
- package/report/renderer/dom.d.ts +0 -13
- package/report/renderer/dom.js +0 -38
- package/report/renderer/performance-category-renderer.d.ts +0 -26
- package/report/renderer/performance-category-renderer.js +10 -142
- package/report/renderer/report-ui-features.d.ts +0 -1
- package/report/renderer/report-ui-features.js +3 -13
- package/report/renderer/report-utils.d.ts +2 -3
- package/report/renderer/report-utils.js +4 -6
- package/report/types/report-renderer.d.ts +0 -6
- package/shared/localization/locales/ar-XB.json +20 -341
- package/shared/localization/locales/ar.json +20 -341
- package/shared/localization/locales/bg.json +9 -330
- package/shared/localization/locales/ca.json +9 -330
- package/shared/localization/locales/cs.json +9 -330
- package/shared/localization/locales/da.json +9 -330
- package/shared/localization/locales/de.json +9 -330
- package/shared/localization/locales/el.json +9 -330
- package/shared/localization/locales/en-GB.json +9 -330
- package/shared/localization/locales/en-US.json +44 -293
- package/shared/localization/locales/en-XA.json +0 -330
- package/shared/localization/locales/en-XL.json +44 -293
- package/shared/localization/locales/es-419.json +9 -330
- package/shared/localization/locales/es.json +9 -330
- package/shared/localization/locales/fi.json +9 -330
- package/shared/localization/locales/fil.json +9 -330
- package/shared/localization/locales/fr.json +9 -330
- package/shared/localization/locales/he.json +31 -352
- package/shared/localization/locales/hi.json +9 -330
- package/shared/localization/locales/hr.json +9 -330
- package/shared/localization/locales/hu.json +9 -330
- package/shared/localization/locales/id.json +9 -330
- package/shared/localization/locales/it.json +9 -330
- package/shared/localization/locales/ja.json +9 -330
- package/shared/localization/locales/ko.json +10 -331
- package/shared/localization/locales/lt.json +9 -330
- package/shared/localization/locales/lv.json +10 -331
- package/shared/localization/locales/nl.json +9 -330
- package/shared/localization/locales/no.json +9 -330
- package/shared/localization/locales/pl.json +9 -330
- package/shared/localization/locales/pt-PT.json +9 -330
- package/shared/localization/locales/pt.json +9 -330
- package/shared/localization/locales/ro.json +10 -331
- package/shared/localization/locales/ru.json +9 -330
- package/shared/localization/locales/sk.json +9 -330
- package/shared/localization/locales/sl.json +9 -330
- package/shared/localization/locales/sr-Latn.json +9 -330
- package/shared/localization/locales/sr.json +9 -330
- package/shared/localization/locales/sv.json +9 -330
- package/shared/localization/locales/ta.json +9 -330
- package/shared/localization/locales/te.json +10 -331
- package/shared/localization/locales/th.json +9 -330
- package/shared/localization/locales/tr.json +9 -330
- package/shared/localization/locales/uk.json +9 -330
- package/shared/localization/locales/vi.json +9 -330
- package/shared/localization/locales/zh-HK.json +9 -330
- package/shared/localization/locales/zh-TW.json +10 -331
- package/shared/localization/locales/zh.json +9 -330
- package/types/artifacts.d.ts +5 -6
- package/types/audit.d.ts +1 -1
- package/types/lhr/settings.d.ts +1 -1
- package/core/audits/byte-efficiency/duplicated-javascript.d.ts +0 -45
- package/core/audits/byte-efficiency/duplicated-javascript.js +0 -223
- package/core/audits/byte-efficiency/efficient-animated-content.d.ts +0 -22
- package/core/audits/byte-efficiency/efficient-animated-content.js +0 -93
- package/core/audits/byte-efficiency/legacy-javascript.d.ts +0 -28
- package/core/audits/byte-efficiency/legacy-javascript.js +0 -144
- package/core/audits/byte-efficiency/modern-image-formats.d.ts +0 -38
- package/core/audits/byte-efficiency/modern-image-formats.js +0 -187
- package/core/audits/byte-efficiency/render-blocking-resources.d.ts +0 -53
- package/core/audits/byte-efficiency/render-blocking-resources.js +0 -312
- package/core/audits/byte-efficiency/uses-long-cache-ttl.d.ts +0 -59
- package/core/audits/byte-efficiency/uses-long-cache-ttl.js +0 -293
- package/core/audits/byte-efficiency/uses-optimized-images.d.ts +0 -33
- package/core/audits/byte-efficiency/uses-optimized-images.js +0 -146
- package/core/audits/byte-efficiency/uses-responsive-images-snapshot.d.ts +0 -16
- package/core/audits/byte-efficiency/uses-responsive-images-snapshot.js +0 -106
- package/core/audits/byte-efficiency/uses-responsive-images.d.ts +0 -44
- package/core/audits/byte-efficiency/uses-responsive-images.js +0 -202
- package/core/audits/byte-efficiency/uses-text-compression.d.ts +0 -14
- package/core/audits/byte-efficiency/uses-text-compression.js +0 -108
- package/core/audits/critical-request-chains.d.ts +0 -44
- package/core/audits/critical-request-chains.js +0 -221
- package/core/audits/dobetterweb/dom-size.d.ts +0 -32
- package/core/audits/dobetterweb/dom-size.js +0 -182
- package/core/audits/dobetterweb/uses-http2.d.ts +0 -72
- package/core/audits/dobetterweb/uses-http2.js +0 -276
- package/core/audits/font-display.d.ts +0 -32
- package/core/audits/font-display.js +0 -195
- package/core/audits/largest-contentful-paint-element.d.ts +0 -34
- package/core/audits/largest-contentful-paint-element.js +0 -181
- package/core/audits/lcp-lazy-loaded.d.ts +0 -22
- package/core/audits/lcp-lazy-loaded.js +0 -115
- package/core/audits/prioritize-lcp-image.d.ts +0 -74
- package/core/audits/prioritize-lcp-image.js +0 -297
- package/core/audits/third-party-summary.d.ts +0 -78
- package/core/audits/third-party-summary.js +0 -236
- package/core/audits/uses-rel-preconnect.d.ts +0 -37
- package/core/audits/uses-rel-preconnect.js +0 -286
- package/core/audits/viewport.d.ts +0 -17
- package/core/audits/viewport.js +0 -87
- package/core/audits/work-during-interaction.d.ts +0 -81
- package/core/audits/work-during-interaction.js +0 -287
- package/core/computed/critical-request-chains.d.ts +0 -42
- package/core/computed/critical-request-chains.js +0 -143
- package/core/computed/viewport-meta.d.ts +0 -37
- package/core/computed/viewport-meta.js +0 -71
- package/types/internal/metaviewport-parser.d.ts +0 -13
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2020 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {Audit} from './audit.js';
|
|
8
|
-
import * as i18n from '../lib/i18n/i18n.js';
|
|
9
|
-
import {NetworkRequest} from '../lib/network-request.js';
|
|
10
|
-
import {MainResource} from '../computed/main-resource.js';
|
|
11
|
-
import {LanternLargestContentfulPaint} from '../computed/metrics/lantern-largest-contentful-paint.js';
|
|
12
|
-
import {LoadSimulator} from '../computed/load-simulator.js';
|
|
13
|
-
import {LCPImageRecord} from '../computed/lcp-image-record.js';
|
|
14
|
-
|
|
15
|
-
const UIStrings = {
|
|
16
|
-
/** Title of a lighthouse audit that tells a user to preload an image in order to improve their LCP time. */
|
|
17
|
-
title: 'Preload Largest Contentful Paint image',
|
|
18
|
-
/** Description of a lighthouse audit that tells a user to preload an image in order to improve their LCP time. */
|
|
19
|
-
description: 'If the LCP element is dynamically added to the page, you should preload the ' +
|
|
20
|
-
'image in order to improve LCP. [Learn more about preloading LCP elements](https://web.dev/articles/optimize-lcp#optimize_when_the_resource_is_discovered).',
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {LH.Crdp.Network.Initiator['type']|'redirect'|'fallbackToMain'} InitiatorType
|
|
27
|
-
* @typedef {Array<{url: string, initiatorType: InitiatorType}>} InitiatorPath
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
class PrioritizeLcpImage extends Audit {
|
|
31
|
-
/**
|
|
32
|
-
* @return {LH.Audit.Meta}
|
|
33
|
-
*/
|
|
34
|
-
static get meta() {
|
|
35
|
-
return {
|
|
36
|
-
id: 'prioritize-lcp-image',
|
|
37
|
-
title: str_(UIStrings.title),
|
|
38
|
-
description: str_(UIStrings.description),
|
|
39
|
-
supportedModes: ['navigation'],
|
|
40
|
-
guidanceLevel: 4,
|
|
41
|
-
requiredArtifacts: ['Trace', 'DevtoolsLog', 'GatherContext', 'URL', 'TraceElements',
|
|
42
|
-
'SourceMaps'],
|
|
43
|
-
scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {LH.Artifacts.NetworkRequest} request
|
|
50
|
-
* @param {LH.Artifacts.NetworkRequest} mainResource
|
|
51
|
-
* @param {InitiatorPath} initiatorPath
|
|
52
|
-
* @return {boolean}
|
|
53
|
-
*/
|
|
54
|
-
static shouldPreloadRequest(request, mainResource, initiatorPath) {
|
|
55
|
-
// If it's already preloaded, no need to recommend it.
|
|
56
|
-
if (request.isLinkPreload) return false;
|
|
57
|
-
// It's not a request loaded over the network, don't recommend it.
|
|
58
|
-
if (NetworkRequest.isNonNetworkRequest(request)) return false;
|
|
59
|
-
// It's already discoverable from the main document (a path of [lcpRecord, mainResource]), don't recommend it.
|
|
60
|
-
if (initiatorPath.length <= 2) return false;
|
|
61
|
-
// Finally, return whether or not it belongs to the main frame
|
|
62
|
-
return request.frameId === mainResource.frameId;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @param {LH.Gatherer.Simulation.GraphNode} graph
|
|
67
|
-
* @param {NetworkRequest} lcpRecord
|
|
68
|
-
* @return {LH.Gatherer.Simulation.GraphNetworkNode|undefined}
|
|
69
|
-
*/
|
|
70
|
-
static findLCPNode(graph, lcpRecord) {
|
|
71
|
-
for (const {node} of graph.traverseGenerator()) {
|
|
72
|
-
if (node.type !== 'network') continue;
|
|
73
|
-
if (node.request.requestId === lcpRecord.requestId) {
|
|
74
|
-
return node;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Get the initiator path starting with lcpRecord back to mainResource, inclusive.
|
|
81
|
-
* Navigation redirects *to* the mainResource are not included.
|
|
82
|
-
* Path returned will always be at least [lcpRecord, mainResource].
|
|
83
|
-
* @param {NetworkRequest} lcpRecord
|
|
84
|
-
* @param {NetworkRequest} mainResource
|
|
85
|
-
* @return {InitiatorPath}
|
|
86
|
-
*/
|
|
87
|
-
static getLcpInitiatorPath(lcpRecord, mainResource) {
|
|
88
|
-
/** @type {InitiatorPath} */
|
|
89
|
-
const initiatorPath = [];
|
|
90
|
-
let mainResourceReached = false;
|
|
91
|
-
/** @type {NetworkRequest|undefined} */
|
|
92
|
-
let request = lcpRecord;
|
|
93
|
-
|
|
94
|
-
while (request) {
|
|
95
|
-
mainResourceReached ||= request.requestId === mainResource.requestId;
|
|
96
|
-
|
|
97
|
-
/** @type {InitiatorType} */
|
|
98
|
-
let initiatorType = request.initiator?.type ?? 'other';
|
|
99
|
-
// Initiator type usually comes from redirect, but 'redirect' is used for more informative debugData.
|
|
100
|
-
if (request.initiatorRequest && request.initiatorRequest === request.redirectSource) {
|
|
101
|
-
initiatorType = 'redirect';
|
|
102
|
-
}
|
|
103
|
-
// Sometimes the initiator chain is broken and the best that can be done is stitch
|
|
104
|
-
// back to the main resource. Note this in the initiatorType.
|
|
105
|
-
if (!request.initiatorRequest && !mainResourceReached) {
|
|
106
|
-
initiatorType = 'fallbackToMain';
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
initiatorPath.push({url: request.url, initiatorType});
|
|
110
|
-
|
|
111
|
-
// Can't preload before the main resource, so break off initiator path there.
|
|
112
|
-
if (mainResourceReached) break;
|
|
113
|
-
|
|
114
|
-
// Continue up chain, falling back to mainResource if chain is broken.
|
|
115
|
-
request = request.initiatorRequest || mainResource;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return initiatorPath;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* @param {LH.Artifacts.NetworkRequest} mainResource
|
|
123
|
-
* @param {LH.Gatherer.Simulation.GraphNode} graph
|
|
124
|
-
* @param {NetworkRequest|undefined} lcpRecord
|
|
125
|
-
* @return {{lcpNodeToPreload?: LH.Gatherer.Simulation.GraphNetworkNode, initiatorPath?: InitiatorPath}}
|
|
126
|
-
*/
|
|
127
|
-
static getLCPNodeToPreload(mainResource, graph, lcpRecord) {
|
|
128
|
-
if (!lcpRecord) return {};
|
|
129
|
-
const lcpNode = PrioritizeLcpImage.findLCPNode(graph, lcpRecord);
|
|
130
|
-
const initiatorPath = PrioritizeLcpImage.getLcpInitiatorPath(lcpRecord, mainResource);
|
|
131
|
-
if (!lcpNode) return {initiatorPath};
|
|
132
|
-
|
|
133
|
-
// eslint-disable-next-line max-len
|
|
134
|
-
const shouldPreload = PrioritizeLcpImage.shouldPreloadRequest(lcpRecord, mainResource, initiatorPath);
|
|
135
|
-
const lcpNodeToPreload = shouldPreload ? lcpNode : undefined;
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
lcpNodeToPreload,
|
|
139
|
-
initiatorPath,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Computes the estimated effect of preloading the LCP image.
|
|
145
|
-
* @param {LH.Artifacts.TraceElement} lcpElement
|
|
146
|
-
* @param {LH.Gatherer.Simulation.GraphNetworkNode|undefined} lcpNode
|
|
147
|
-
* @param {LH.Gatherer.Simulation.GraphNode} graph
|
|
148
|
-
* @param {LH.Gatherer.Simulation.Simulator} simulator
|
|
149
|
-
* @return {{wastedMs: number, results: Array<{node: LH.Audit.Details.NodeValue, url: string, wastedMs: number}>}}
|
|
150
|
-
*/
|
|
151
|
-
static computeWasteWithGraph(lcpElement, lcpNode, graph, simulator) {
|
|
152
|
-
if (!lcpNode) {
|
|
153
|
-
return {
|
|
154
|
-
wastedMs: 0,
|
|
155
|
-
results: [],
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const modifiedGraph = graph.cloneWithRelationships();
|
|
160
|
-
|
|
161
|
-
// Store the IDs of the LCP Node's dependencies for later
|
|
162
|
-
/** @type {Set<string>} */
|
|
163
|
-
const dependenciesIds = new Set();
|
|
164
|
-
for (const node of lcpNode.getDependencies()) {
|
|
165
|
-
dependenciesIds.add(node.id);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/** @type {LH.Gatherer.Simulation.GraphNode|null} */
|
|
169
|
-
let modifiedLCPNode = null;
|
|
170
|
-
/** @type {LH.Gatherer.Simulation.GraphNode|null} */
|
|
171
|
-
let mainDocumentNode = null;
|
|
172
|
-
|
|
173
|
-
for (const {node} of modifiedGraph.traverseGenerator()) {
|
|
174
|
-
if (node.type !== 'network') continue;
|
|
175
|
-
|
|
176
|
-
if (node.isMainDocument()) {
|
|
177
|
-
mainDocumentNode = node;
|
|
178
|
-
} else if (node.id === lcpNode.id) {
|
|
179
|
-
modifiedLCPNode = node;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (!mainDocumentNode) {
|
|
184
|
-
// Should always find the main document node
|
|
185
|
-
throw new Error('Could not find main document node');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
if (!modifiedLCPNode) {
|
|
189
|
-
// Should always find the LCP node as well or else this function wouldn't have been called
|
|
190
|
-
throw new Error('Could not find the LCP node');
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// Preload will request the resource as soon as its discovered in the main document.
|
|
194
|
-
// Reflect this change in the dependencies in our modified graph.
|
|
195
|
-
modifiedLCPNode.removeAllDependencies();
|
|
196
|
-
modifiedLCPNode.addDependency(mainDocumentNode);
|
|
197
|
-
|
|
198
|
-
const simulationBeforeChanges = simulator.simulate(graph);
|
|
199
|
-
const simulationAfterChanges = simulator.simulate(modifiedGraph);
|
|
200
|
-
const lcpTimingsBefore = simulationBeforeChanges.nodeTimings.get(lcpNode);
|
|
201
|
-
if (!lcpTimingsBefore) throw new Error('Impossible - node timings should never be undefined');
|
|
202
|
-
const lcpTimingsAfter = simulationAfterChanges.nodeTimings.get(modifiedLCPNode);
|
|
203
|
-
if (!lcpTimingsAfter) throw new Error('Impossible - node timings should never be undefined');
|
|
204
|
-
/** @type {Map<String, LH.Gatherer.Simulation.GraphNode>} */
|
|
205
|
-
const modifiedNodesById = Array.from(simulationAfterChanges.nodeTimings.keys())
|
|
206
|
-
.reduce((map, node) => map.set(node.id, node), new Map());
|
|
207
|
-
|
|
208
|
-
// Even with preload, the image can't be painted before it's even inserted into the DOM.
|
|
209
|
-
// New LCP time will be the max of image download and image in DOM (endTime of its deps).
|
|
210
|
-
let maxDependencyEndTime = 0;
|
|
211
|
-
for (const nodeId of Array.from(dependenciesIds)) {
|
|
212
|
-
const node = modifiedNodesById.get(nodeId);
|
|
213
|
-
if (!node) throw new Error('Impossible - node should never be undefined');
|
|
214
|
-
const timings = simulationAfterChanges.nodeTimings.get(node);
|
|
215
|
-
const endTime = timings?.endTime || 0;
|
|
216
|
-
maxDependencyEndTime = Math.max(maxDependencyEndTime, endTime);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const wastedMs = lcpTimingsBefore.endTime -
|
|
220
|
-
Math.max(lcpTimingsAfter.endTime, maxDependencyEndTime);
|
|
221
|
-
|
|
222
|
-
return {
|
|
223
|
-
wastedMs,
|
|
224
|
-
results: [{
|
|
225
|
-
node: Audit.makeNodeItem(lcpElement.node),
|
|
226
|
-
url: lcpNode.request.url,
|
|
227
|
-
wastedMs,
|
|
228
|
-
}],
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* @param {LH.Artifacts} artifacts
|
|
234
|
-
* @param {LH.Audit.Context} context
|
|
235
|
-
* @return {Promise<LH.Audit.Product>}
|
|
236
|
-
*/
|
|
237
|
-
static async audit(artifacts, context) {
|
|
238
|
-
const gatherContext = artifacts.GatherContext;
|
|
239
|
-
const trace = artifacts.Trace;
|
|
240
|
-
const devtoolsLog = artifacts.DevtoolsLog;
|
|
241
|
-
const {URL, SourceMaps} = artifacts;
|
|
242
|
-
const settings = context.settings;
|
|
243
|
-
const metricData =
|
|
244
|
-
{trace, devtoolsLog, gatherContext, settings, URL, SourceMaps, simulator: null};
|
|
245
|
-
const lcpElement = artifacts.TraceElements
|
|
246
|
-
.find(element => element.traceEventType === 'largest-contentful-paint');
|
|
247
|
-
|
|
248
|
-
if (!lcpElement || lcpElement.type !== 'image') {
|
|
249
|
-
return {score: null, notApplicable: true, metricSavings: {LCP: 0}};
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const mainResource = await MainResource.request({devtoolsLog, URL}, context);
|
|
253
|
-
const lanternLCP = await LanternLargestContentfulPaint.request(metricData, context);
|
|
254
|
-
const simulator = await LoadSimulator.request({devtoolsLog, settings}, context);
|
|
255
|
-
|
|
256
|
-
const lcpImageRecord = await LCPImageRecord.request({trace, devtoolsLog}, context);
|
|
257
|
-
const graph = lanternLCP.pessimisticGraph;
|
|
258
|
-
// Note: if moving to LCPAllFrames, mainResource would need to be the LCP frame's main resource.
|
|
259
|
-
const {lcpNodeToPreload, initiatorPath} = PrioritizeLcpImage.getLCPNodeToPreload(mainResource,
|
|
260
|
-
graph, lcpImageRecord);
|
|
261
|
-
|
|
262
|
-
const {results, wastedMs} =
|
|
263
|
-
PrioritizeLcpImage.computeWasteWithGraph(lcpElement, lcpNodeToPreload, graph, simulator);
|
|
264
|
-
|
|
265
|
-
/** @type {LH.Audit.Details.Opportunity['headings']} */
|
|
266
|
-
const headings = [
|
|
267
|
-
{key: 'node', valueType: 'node', label: ''},
|
|
268
|
-
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
|
|
269
|
-
{key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnWastedMs)},
|
|
270
|
-
];
|
|
271
|
-
const details = Audit.makeOpportunityDetails(headings, results,
|
|
272
|
-
{overallSavingsMs: wastedMs, sortedBy: ['wastedMs']});
|
|
273
|
-
|
|
274
|
-
// If LCP element was an image and had valid network records (regardless of
|
|
275
|
-
// if it should be preloaded), it will be found first in the `initiatorPath`.
|
|
276
|
-
// Otherwise path and length will be undefined.
|
|
277
|
-
if (initiatorPath) {
|
|
278
|
-
details.debugData = {
|
|
279
|
-
type: 'debugdata',
|
|
280
|
-
initiatorPath,
|
|
281
|
-
pathLength: initiatorPath.length,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
score: results.length ? 0 : 1,
|
|
287
|
-
numericValue: wastedMs,
|
|
288
|
-
numericUnit: 'millisecond',
|
|
289
|
-
displayValue: wastedMs ? str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) : '',
|
|
290
|
-
details,
|
|
291
|
-
metricSavings: {LCP: wastedMs},
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
export default PrioritizeLcpImage;
|
|
297
|
-
export {UIStrings};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export default ThirdPartySummary;
|
|
2
|
-
export type Summary = {
|
|
3
|
-
mainThreadTime: number;
|
|
4
|
-
transferSize: number;
|
|
5
|
-
blockingTime: number;
|
|
6
|
-
tbtImpact: number;
|
|
7
|
-
};
|
|
8
|
-
export type URLSummary = {
|
|
9
|
-
transferSize: number;
|
|
10
|
-
blockingTime: number;
|
|
11
|
-
tbtImpact: number;
|
|
12
|
-
url: string | LH.IcuMessage;
|
|
13
|
-
};
|
|
14
|
-
export type SummaryMaps = {
|
|
15
|
-
/**
|
|
16
|
-
* Map of impact summaries for each entity.
|
|
17
|
-
*/
|
|
18
|
-
byEntity: Map<LH.Artifacts.Entity, Summary>;
|
|
19
|
-
/**
|
|
20
|
-
* Map of impact summaries for each URL.
|
|
21
|
-
*/
|
|
22
|
-
byURL: Map<string, Summary>;
|
|
23
|
-
/**
|
|
24
|
-
* Map of URLs under each entity.
|
|
25
|
-
*/
|
|
26
|
-
urls: Map<LH.Artifacts.Entity, string[]>;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* @typedef Summary
|
|
30
|
-
* @property {number} mainThreadTime
|
|
31
|
-
* @property {number} transferSize
|
|
32
|
-
* @property {number} blockingTime
|
|
33
|
-
* @property {number} tbtImpact
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @typedef URLSummary
|
|
37
|
-
* @property {number} transferSize
|
|
38
|
-
* @property {number} blockingTime
|
|
39
|
-
* @property {number} tbtImpact
|
|
40
|
-
* @property {string | LH.IcuMessage} url
|
|
41
|
-
*/
|
|
42
|
-
/** @typedef SummaryMaps
|
|
43
|
-
* @property {Map<LH.Artifacts.Entity, Summary>} byEntity Map of impact summaries for each entity.
|
|
44
|
-
* @property {Map<string, Summary>} byURL Map of impact summaries for each URL.
|
|
45
|
-
* @property {Map<LH.Artifacts.Entity, string[]>} urls Map of URLs under each entity.
|
|
46
|
-
*/
|
|
47
|
-
declare class ThirdPartySummary extends Audit {
|
|
48
|
-
/**
|
|
49
|
-
*
|
|
50
|
-
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
|
|
51
|
-
* @param {Array<LH.Artifacts.TBTImpactTask>} tbtImpactTasks
|
|
52
|
-
* @param {number} cpuMultiplier
|
|
53
|
-
* @param {LH.Artifacts.EntityClassification} entityClassification
|
|
54
|
-
* @return {SummaryMaps}
|
|
55
|
-
*/
|
|
56
|
-
static getSummaries(networkRecords: Array<LH.Artifacts.NetworkRequest>, tbtImpactTasks: Array<LH.Artifacts.TBTImpactTask>, cpuMultiplier: number, entityClassification: LH.Artifacts.EntityClassification): SummaryMaps;
|
|
57
|
-
/**
|
|
58
|
-
* @param {LH.Artifacts.Entity} entity
|
|
59
|
-
* @param {SummaryMaps} summaries
|
|
60
|
-
* @return {Array<URLSummary>}
|
|
61
|
-
*/
|
|
62
|
-
static makeSubItems(entity: LH.Artifacts.Entity, summaries: SummaryMaps): Array<URLSummary>;
|
|
63
|
-
/**
|
|
64
|
-
* @param {LH.Artifacts} artifacts
|
|
65
|
-
* @param {LH.Audit.Context} context
|
|
66
|
-
* @return {Promise<LH.Audit.Product>}
|
|
67
|
-
*/
|
|
68
|
-
static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
|
|
69
|
-
}
|
|
70
|
-
export namespace UIStrings {
|
|
71
|
-
let title: string;
|
|
72
|
-
let failureTitle: string;
|
|
73
|
-
let description: string;
|
|
74
|
-
let columnThirdParty: string;
|
|
75
|
-
let displayValue: string;
|
|
76
|
-
}
|
|
77
|
-
import { Audit } from './audit.js';
|
|
78
|
-
//# sourceMappingURL=third-party-summary.d.ts.map
|
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2019 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import {Audit} from './audit.js';
|
|
8
|
-
import {EntityClassification} from '../computed/entity-classification.js';
|
|
9
|
-
import * as i18n from '../lib/i18n/i18n.js';
|
|
10
|
-
import {NetworkRecords} from '../computed/network-records.js';
|
|
11
|
-
import {getJavaScriptURLs, getAttributableURLForTask} from '../lib/tracehouse/task-summary.js';
|
|
12
|
-
import {TBTImpactTasks} from '../computed/tbt-impact-tasks.js';
|
|
13
|
-
|
|
14
|
-
const UIStrings = {
|
|
15
|
-
/** Title of a diagnostic audit that provides details about the code on a web page that the user doesn't control (referred to as "third-party code"). This descriptive title is shown to users when the amount is acceptable and no user action is required. */
|
|
16
|
-
title: 'Minimize third-party usage',
|
|
17
|
-
/** Title of a diagnostic audit that provides details about the code on a web page that the user doesn't control (referred to as "third-party code"). This imperative title is shown to users when there is a significant amount of page execution time caused by third-party code that should be reduced. */
|
|
18
|
-
failureTitle: 'Reduce the impact of third-party code',
|
|
19
|
-
/** Description of a Lighthouse audit that identifies the code on the page that the user doesn't control. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
|
|
20
|
-
description: 'Third-party code can significantly impact load performance. ' +
|
|
21
|
-
'Limit the number of redundant third-party providers and try to load third-party code after ' +
|
|
22
|
-
'your page has primarily finished loading. ' +
|
|
23
|
-
'[Learn how to minimize third-party impact](https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/loading-third-party-javascript/).',
|
|
24
|
-
/** Label for a table column that displays the name of a third-party provider that potentially links to their website. */
|
|
25
|
-
columnThirdParty: 'Third-Party',
|
|
26
|
-
/** Summary text for the result of a Lighthouse audit that identifies the code on a web page that the user doesn't control (referred to as "third-party code"). This text summarizes the number of distinct entities that were found on the page. */
|
|
27
|
-
displayValue: 'Third-party code blocked the main thread for ' +
|
|
28
|
-
`{timeInMs, number, milliseconds}\xa0ms`,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
|
|
32
|
-
|
|
33
|
-
// A page passes when all third-party code blocks for less than 250 ms.
|
|
34
|
-
const PASS_THRESHOLD_IN_MS = 250;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @typedef Summary
|
|
38
|
-
* @property {number} mainThreadTime
|
|
39
|
-
* @property {number} transferSize
|
|
40
|
-
* @property {number} blockingTime
|
|
41
|
-
* @property {number} tbtImpact
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @typedef URLSummary
|
|
46
|
-
* @property {number} transferSize
|
|
47
|
-
* @property {number} blockingTime
|
|
48
|
-
* @property {number} tbtImpact
|
|
49
|
-
* @property {string | LH.IcuMessage} url
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
/** @typedef SummaryMaps
|
|
53
|
-
* @property {Map<LH.Artifacts.Entity, Summary>} byEntity Map of impact summaries for each entity.
|
|
54
|
-
* @property {Map<string, Summary>} byURL Map of impact summaries for each URL.
|
|
55
|
-
* @property {Map<LH.Artifacts.Entity, string[]>} urls Map of URLs under each entity.
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
class ThirdPartySummary extends Audit {
|
|
59
|
-
/**
|
|
60
|
-
* @return {LH.Audit.Meta}
|
|
61
|
-
*/
|
|
62
|
-
static get meta() {
|
|
63
|
-
return {
|
|
64
|
-
id: 'third-party-summary',
|
|
65
|
-
title: str_(UIStrings.title),
|
|
66
|
-
failureTitle: str_(UIStrings.failureTitle),
|
|
67
|
-
description: str_(UIStrings.description),
|
|
68
|
-
guidanceLevel: 1,
|
|
69
|
-
scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
|
|
70
|
-
requiredArtifacts: ['Trace', 'DevtoolsLog', 'URL', 'GatherContext', 'SourceMaps'],
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @param {Array<LH.Artifacts.NetworkRequest>} networkRecords
|
|
77
|
-
* @param {Array<LH.Artifacts.TBTImpactTask>} tbtImpactTasks
|
|
78
|
-
* @param {number} cpuMultiplier
|
|
79
|
-
* @param {LH.Artifacts.EntityClassification} entityClassification
|
|
80
|
-
* @return {SummaryMaps}
|
|
81
|
-
*/
|
|
82
|
-
static getSummaries(networkRecords, tbtImpactTasks, cpuMultiplier, entityClassification) {
|
|
83
|
-
/** @type {Map<string, Summary>} */
|
|
84
|
-
const byURL = new Map();
|
|
85
|
-
/** @type {Map<LH.Artifacts.Entity, Summary>} */
|
|
86
|
-
const byEntity = new Map();
|
|
87
|
-
const defaultSummary = {mainThreadTime: 0, blockingTime: 0, transferSize: 0, tbtImpact: 0};
|
|
88
|
-
|
|
89
|
-
for (const request of networkRecords) {
|
|
90
|
-
const urlSummary = byURL.get(request.url) || {...defaultSummary};
|
|
91
|
-
urlSummary.transferSize += request.transferSize;
|
|
92
|
-
byURL.set(request.url, urlSummary);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const jsURLs = getJavaScriptURLs(networkRecords);
|
|
96
|
-
|
|
97
|
-
for (const task of tbtImpactTasks) {
|
|
98
|
-
const attributableURL = getAttributableURLForTask(task, jsURLs);
|
|
99
|
-
|
|
100
|
-
const urlSummary = byURL.get(attributableURL) || {...defaultSummary};
|
|
101
|
-
const taskDuration = task.selfTime * cpuMultiplier;
|
|
102
|
-
// The amount of time spent on main thread is the sum of all durations.
|
|
103
|
-
urlSummary.mainThreadTime += taskDuration;
|
|
104
|
-
// Blocking time is the amount of time spent on the main thread *over* 50ms.
|
|
105
|
-
// This value is interpolated because not all tasks attributed to this URL are at the top level.
|
|
106
|
-
//
|
|
107
|
-
// Note that this is not totally equivalent to the TBT definition since it fails to account for
|
|
108
|
-
// the FCP&TTI bounds of TBT.
|
|
109
|
-
urlSummary.blockingTime += task.selfBlockingTime;
|
|
110
|
-
// TBT impact is similar to blocking time, but it accounts for the FCP&TTI bounds of TBT.
|
|
111
|
-
urlSummary.tbtImpact += task.selfTbtImpact;
|
|
112
|
-
byURL.set(attributableURL, urlSummary);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Map each URL's stat to a particular entity.
|
|
116
|
-
/** @type {Map<LH.Artifacts.Entity, string[]>} */
|
|
117
|
-
const urls = new Map();
|
|
118
|
-
for (const [url, urlSummary] of byURL.entries()) {
|
|
119
|
-
const entity = entityClassification.entityByUrl.get(url);
|
|
120
|
-
if (!entity) {
|
|
121
|
-
byURL.delete(url);
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const entitySummary = byEntity.get(entity) || {...defaultSummary};
|
|
126
|
-
entitySummary.transferSize += urlSummary.transferSize;
|
|
127
|
-
entitySummary.mainThreadTime += urlSummary.mainThreadTime;
|
|
128
|
-
entitySummary.blockingTime += urlSummary.blockingTime;
|
|
129
|
-
entitySummary.tbtImpact += urlSummary.tbtImpact;
|
|
130
|
-
byEntity.set(entity, entitySummary);
|
|
131
|
-
|
|
132
|
-
const entityURLs = urls.get(entity) || [];
|
|
133
|
-
entityURLs.push(url);
|
|
134
|
-
urls.set(entity, entityURLs);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {byURL, byEntity, urls};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* @param {LH.Artifacts.Entity} entity
|
|
142
|
-
* @param {SummaryMaps} summaries
|
|
143
|
-
* @return {Array<URLSummary>}
|
|
144
|
-
*/
|
|
145
|
-
static makeSubItems(entity, summaries) {
|
|
146
|
-
const entityURLs = summaries.urls.get(entity) || [];
|
|
147
|
-
const items = entityURLs
|
|
148
|
-
.map(url => /** @type {URLSummary} */ ({url, ...summaries.byURL.get(url)}))
|
|
149
|
-
// Sort by blocking time first, then transfer size to break ties.
|
|
150
|
-
.sort((a, b) => (b.blockingTime - a.blockingTime) || (b.transferSize - a.transferSize));
|
|
151
|
-
|
|
152
|
-
return items;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @param {LH.Artifacts} artifacts
|
|
157
|
-
* @param {LH.Audit.Context} context
|
|
158
|
-
* @return {Promise<LH.Audit.Product>}
|
|
159
|
-
*/
|
|
160
|
-
static async audit(artifacts, context) {
|
|
161
|
-
const settings = context.settings || {};
|
|
162
|
-
const devtoolsLog = artifacts.DevtoolsLog;
|
|
163
|
-
const networkRecords = await NetworkRecords.request(devtoolsLog, context);
|
|
164
|
-
const classifiedEntities = await EntityClassification.request(
|
|
165
|
-
{URL: artifacts.URL, devtoolsLog}, context);
|
|
166
|
-
const firstPartyEntity = classifiedEntities.firstParty;
|
|
167
|
-
|
|
168
|
-
const metricComputationData = Audit.makeMetricComputationDataInput(artifacts, context);
|
|
169
|
-
const tbtImpactTasks = await TBTImpactTasks.request(metricComputationData, context);
|
|
170
|
-
|
|
171
|
-
const multiplier = settings.throttlingMethod === 'simulate' ?
|
|
172
|
-
settings.throttling.cpuSlowdownMultiplier : 1;
|
|
173
|
-
|
|
174
|
-
const summaries = ThirdPartySummary.getSummaries(
|
|
175
|
-
networkRecords, tbtImpactTasks, multiplier, classifiedEntities);
|
|
176
|
-
const overallSummary = {wastedBytes: 0, wastedMs: 0, tbtImpact: 0};
|
|
177
|
-
|
|
178
|
-
const results = Array.from(summaries.byEntity.entries())
|
|
179
|
-
// Don't consider the page we're on to be third-party.
|
|
180
|
-
// e.g. Facebook SDK isn't a third-party script on facebook.com
|
|
181
|
-
.filter(([entity]) => !(firstPartyEntity && firstPartyEntity === entity))
|
|
182
|
-
.map(([entity, stats]) => {
|
|
183
|
-
overallSummary.wastedBytes += stats.transferSize;
|
|
184
|
-
overallSummary.wastedMs += stats.blockingTime;
|
|
185
|
-
overallSummary.tbtImpact += stats.tbtImpact;
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
...stats,
|
|
189
|
-
entity: entity.name,
|
|
190
|
-
subItems: {
|
|
191
|
-
type: /** @type {const} */ ('subitems'),
|
|
192
|
-
items: ThirdPartySummary.makeSubItems(entity, summaries),
|
|
193
|
-
},
|
|
194
|
-
};
|
|
195
|
-
})
|
|
196
|
-
// Sort by blocking time first, then transfer size to break ties.
|
|
197
|
-
.sort((a, b) => (b.blockingTime - a.blockingTime) || (b.transferSize - a.transferSize));
|
|
198
|
-
|
|
199
|
-
/** @type {LH.Audit.Details.Table['headings']} */
|
|
200
|
-
const headings = [
|
|
201
|
-
/* eslint-disable max-len */
|
|
202
|
-
{key: 'entity', valueType: 'text', label: str_(UIStrings.columnThirdParty), subItemsHeading: {key: 'url', valueType: 'url'}},
|
|
203
|
-
{key: 'transferSize', granularity: 1, valueType: 'bytes', label: str_(i18n.UIStrings.columnTransferSize), subItemsHeading: {key: 'transferSize'}},
|
|
204
|
-
{key: 'blockingTime', granularity: 1, valueType: 'ms', label: str_(i18n.UIStrings.columnBlockingTime), subItemsHeading: {key: 'blockingTime'}},
|
|
205
|
-
/* eslint-enable max-len */
|
|
206
|
-
];
|
|
207
|
-
|
|
208
|
-
if (!results.length) {
|
|
209
|
-
return {
|
|
210
|
-
score: 1,
|
|
211
|
-
notApplicable: true,
|
|
212
|
-
metricSavings: {TBT: 0},
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const details = Audit.makeTableDetails(headings, results,
|
|
217
|
-
{...overallSummary, isEntityGrouped: true});
|
|
218
|
-
|
|
219
|
-
const passed = overallSummary.wastedMs <= PASS_THRESHOLD_IN_MS;
|
|
220
|
-
|
|
221
|
-
return {
|
|
222
|
-
score: Number(passed),
|
|
223
|
-
scoreDisplayMode: passed ? Audit.SCORING_MODES.INFORMATIVE : undefined,
|
|
224
|
-
displayValue: str_(UIStrings.displayValue, {
|
|
225
|
-
timeInMs: overallSummary.wastedMs,
|
|
226
|
-
}),
|
|
227
|
-
details,
|
|
228
|
-
metricSavings: {
|
|
229
|
-
TBT: Math.round(overallSummary.tbtImpact),
|
|
230
|
-
},
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
export default ThirdPartySummary;
|
|
236
|
-
export {UIStrings};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
export default UsesRelPreconnectAudit;
|
|
2
|
-
declare class UsesRelPreconnectAudit extends Audit {
|
|
3
|
-
/**
|
|
4
|
-
* Check if record has valid timing
|
|
5
|
-
* @param {LH.Artifacts.NetworkRequest} record
|
|
6
|
-
* @return {boolean}
|
|
7
|
-
*/
|
|
8
|
-
static hasValidTiming(record: LH.Artifacts.NetworkRequest): boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Check is the connection is already open
|
|
11
|
-
* @param {LH.Artifacts.NetworkRequest} record
|
|
12
|
-
* @return {boolean}
|
|
13
|
-
*/
|
|
14
|
-
static hasAlreadyConnectedToOrigin(record: LH.Artifacts.NetworkRequest): boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Check is the connection has started before the socket idle time
|
|
17
|
-
* @param {LH.Artifacts.NetworkRequest} record
|
|
18
|
-
* @param {LH.Artifacts.NetworkRequest} mainResource
|
|
19
|
-
* @return {boolean}
|
|
20
|
-
*/
|
|
21
|
-
static socketStartTimeIsBelowThreshold(record: LH.Artifacts.NetworkRequest, mainResource: LH.Artifacts.NetworkRequest): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* @param {LH.Artifacts} artifacts
|
|
24
|
-
* @param {LH.Audit.Context} context
|
|
25
|
-
* @return {Promise<LH.Audit.Product>}
|
|
26
|
-
*/
|
|
27
|
-
static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
|
|
28
|
-
}
|
|
29
|
-
export namespace UIStrings {
|
|
30
|
-
let title: string;
|
|
31
|
-
let description: string;
|
|
32
|
-
let unusedWarning: string;
|
|
33
|
-
let crossoriginWarning: string;
|
|
34
|
-
let tooManyPreconnectLinksWarning: string;
|
|
35
|
-
}
|
|
36
|
-
import { Audit } from './audit.js';
|
|
37
|
-
//# sourceMappingURL=uses-rel-preconnect.d.ts.map
|