lighthouse 12.8.2-dev.20250930 → 12.8.2-dev.20251002

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.
Files changed (55) hide show
  1. package/core/config/experimental-config.js +0 -6
  2. package/core/gather/gatherers/trace-elements.js +6 -1
  3. package/package.json +1 -1
  4. package/shared/localization/locales/ar-XB.json +0 -18
  5. package/shared/localization/locales/ar.json +0 -18
  6. package/shared/localization/locales/bg.json +0 -18
  7. package/shared/localization/locales/ca.json +0 -18
  8. package/shared/localization/locales/cs.json +0 -18
  9. package/shared/localization/locales/da.json +0 -18
  10. package/shared/localization/locales/de.json +0 -18
  11. package/shared/localization/locales/el.json +0 -18
  12. package/shared/localization/locales/en-GB.json +0 -18
  13. package/shared/localization/locales/en-US.json +0 -18
  14. package/shared/localization/locales/en-XA.json +0 -18
  15. package/shared/localization/locales/en-XL.json +0 -18
  16. package/shared/localization/locales/es-419.json +0 -18
  17. package/shared/localization/locales/es.json +0 -18
  18. package/shared/localization/locales/fi.json +0 -18
  19. package/shared/localization/locales/fil.json +0 -18
  20. package/shared/localization/locales/fr.json +0 -18
  21. package/shared/localization/locales/he.json +0 -18
  22. package/shared/localization/locales/hi.json +0 -18
  23. package/shared/localization/locales/hr.json +0 -18
  24. package/shared/localization/locales/hu.json +0 -18
  25. package/shared/localization/locales/id.json +0 -18
  26. package/shared/localization/locales/it.json +0 -18
  27. package/shared/localization/locales/ja.json +0 -18
  28. package/shared/localization/locales/ko.json +0 -18
  29. package/shared/localization/locales/lt.json +0 -18
  30. package/shared/localization/locales/lv.json +0 -18
  31. package/shared/localization/locales/nl.json +0 -18
  32. package/shared/localization/locales/no.json +0 -18
  33. package/shared/localization/locales/pl.json +0 -18
  34. package/shared/localization/locales/pt-PT.json +0 -18
  35. package/shared/localization/locales/pt.json +0 -18
  36. package/shared/localization/locales/ro.json +0 -18
  37. package/shared/localization/locales/ru.json +0 -18
  38. package/shared/localization/locales/sk.json +0 -18
  39. package/shared/localization/locales/sl.json +0 -18
  40. package/shared/localization/locales/sr-Latn.json +0 -18
  41. package/shared/localization/locales/sr.json +0 -18
  42. package/shared/localization/locales/sv.json +0 -18
  43. package/shared/localization/locales/ta.json +0 -18
  44. package/shared/localization/locales/te.json +0 -18
  45. package/shared/localization/locales/th.json +0 -18
  46. package/shared/localization/locales/tr.json +0 -18
  47. package/shared/localization/locales/uk.json +0 -18
  48. package/shared/localization/locales/vi.json +0 -18
  49. package/shared/localization/locales/zh-HK.json +0 -18
  50. package/shared/localization/locales/zh-TW.json +0 -18
  51. package/shared/localization/locales/zh.json +0 -18
  52. package/core/audits/preload-fonts.d.ts +0 -25
  53. package/core/audits/preload-fonts.js +0 -97
  54. package/core/audits/uses-rel-preload.d.ts +0 -57
  55. package/core/audits/uses-rel-preload.js +0 -263
@@ -1,57 +0,0 @@
1
- export default UsesRelPreloadAudit;
2
- declare class UsesRelPreloadAudit extends Audit {
3
- /**
4
- * @param {LH.Artifacts.NetworkRequest} mainResource
5
- * @param {LH.Gatherer.Simulation.GraphNode} graph
6
- * @return {Set<string>}
7
- */
8
- static getURLsToPreload(mainResource: LH.Artifacts.NetworkRequest, graph: LH.Gatherer.Simulation.GraphNode): Set<string>;
9
- /**
10
- * Finds which URLs were attempted to be preloaded, but failed to be reused and were requested again.
11
- *
12
- * @param {LH.Gatherer.Simulation.GraphNode} graph
13
- * @return {Set<string>}
14
- */
15
- static getURLsFailedToPreload(graph: LH.Gatherer.Simulation.GraphNode): Set<string>;
16
- /**
17
- * We want to preload all first party critical requests at depth 2.
18
- * Third party requests can be tricky to know the URL ahead of time.
19
- * Critical requests at depth 1 would already be identified by the browser for preloading.
20
- * Critical requests deeper than depth 2 are more likely to be a case-by-case basis such that it
21
- * would be a little risky to recommend blindly.
22
- *
23
- * @param {Lantern.Types.NetworkRequest} request
24
- * @param {Lantern.Types.NetworkRequest} mainResource
25
- * @param {Array<LH.Gatherer.Simulation.GraphNode>} initiatorPath
26
- * @return {boolean}
27
- */
28
- static shouldPreloadRequest(request: Lantern.Types.NetworkRequest, mainResource: Lantern.Types.NetworkRequest, initiatorPath: Array<LH.Gatherer.Simulation.GraphNode>): boolean;
29
- /**
30
- * Computes the estimated effect of preloading all the resources.
31
- * @param {Set<string>} urls The array of byte savings results per resource
32
- * @param {LH.Gatherer.Simulation.GraphNode} graph
33
- * @param {LH.Gatherer.Simulation.Simulator} simulator
34
- * @return {{wastedMs: number, results: Array<{url: string, wastedMs: number}>}}
35
- */
36
- static computeWasteWithGraph(urls: Set<string>, graph: LH.Gatherer.Simulation.GraphNode, simulator: LH.Gatherer.Simulation.Simulator): {
37
- wastedMs: number;
38
- results: Array<{
39
- url: string;
40
- wastedMs: number;
41
- }>;
42
- };
43
- /**
44
- * @param {LH.Artifacts} artifacts
45
- * @param {LH.Audit.Context} context
46
- * @return {Promise<LH.Audit.Product>}
47
- */
48
- static audit(artifacts: LH.Artifacts, context: LH.Audit.Context): Promise<LH.Audit.Product>;
49
- }
50
- export namespace UIStrings {
51
- let title: string;
52
- let description: string;
53
- let crossoriginWarning: string;
54
- }
55
- import { Audit } from './audit.js';
56
- import * as Lantern from '../lib/lantern/lantern.js';
57
- //# sourceMappingURL=uses-rel-preload.d.ts.map
@@ -1,263 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
-
7
- import * as Lantern from '../lib/lantern/lantern.js';
8
- import UrlUtils from '../lib/url-utils.js';
9
- import {NetworkRequest} from '../lib/network-request.js';
10
- import {Audit} from './audit.js';
11
- import {CriticalRequestChains} from '../computed/critical-request-chains.js';
12
- import * as i18n from '../lib/i18n/i18n.js';
13
- import {MainResource} from '../computed/main-resource.js';
14
- import {PageDependencyGraph} from '../computed/page-dependency-graph.js';
15
- import {LoadSimulator} from '../computed/load-simulator.js';
16
-
17
- const UIStrings = {
18
- /** Imperative title of a Lighthouse audit that tells the user to use <link rel=preload> to initiate important network requests earlier during page load. This is displayed in a list of audit titles that Lighthouse generates. */
19
- title: 'Preload key requests',
20
- /** Description of a Lighthouse audit that tells the user *why* they should preload important network requests. The associated network requests are started halfway through pageload (or later) but should be started at the beginning. This is displayed after a user expands the section to see more. No character length limits. '<link rel=preload>' is the html code the user would include in their page and shouldn't be translated. The last sentence starting with 'Learn' becomes link text to additional documentation. */
21
- description: 'Consider using `<link rel=preload>` to prioritize fetching resources that are ' +
22
- 'currently requested later in page load. ' +
23
- '[Learn how to preload key requests](https://developer.chrome.com/docs/lighthouse/performance/uses-rel-preload/).',
24
- /**
25
- * @description A warning message that is shown when the user tried to follow the advice of the audit, but it's not working as expected. Forgetting to set the `crossorigin` HTML attribute, or setting it to an incorrect value, on the link is a common mistake when adding preload links.
26
- * @example {https://example.com} preloadURL
27
- * */
28
- crossoriginWarning: 'A preload `<link>` was found for "{preloadURL}" but was not used ' +
29
- 'by the browser. Check that you are using the `crossorigin` attribute properly.',
30
- };
31
-
32
- const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);
33
-
34
- const THRESHOLD_IN_MS = 100;
35
-
36
- class UsesRelPreloadAudit extends Audit {
37
- /**
38
- * @return {LH.Audit.Meta}
39
- */
40
- static get meta() {
41
- return {
42
- id: 'uses-rel-preload',
43
- title: str_(UIStrings.title),
44
- description: str_(UIStrings.description),
45
- supportedModes: ['navigation'],
46
- guidanceLevel: 3,
47
- requiredArtifacts: ['DevtoolsLog', 'Trace', 'URL', 'SourceMaps'],
48
- scoreDisplayMode: Audit.SCORING_MODES.METRIC_SAVINGS,
49
- };
50
- }
51
-
52
- /**
53
- * @param {LH.Artifacts.NetworkRequest} mainResource
54
- * @param {LH.Gatherer.Simulation.GraphNode} graph
55
- * @return {Set<string>}
56
- */
57
- static getURLsToPreload(mainResource, graph) {
58
- /** @type {Set<string>} */
59
- const urls = new Set();
60
-
61
- graph.traverse((node, traversalPath) => {
62
- if (node.type !== 'network') return;
63
- // Don't include the node itself or any CPU nodes in the initiatorPath
64
- const path = traversalPath.slice(1).filter(initiator => initiator.type === 'network');
65
- if (!UsesRelPreloadAudit.shouldPreloadRequest(node.request, mainResource, path)) return;
66
- urls.add(node.request.url);
67
- });
68
-
69
- return urls;
70
- }
71
-
72
- /**
73
- * Finds which URLs were attempted to be preloaded, but failed to be reused and were requested again.
74
- *
75
- * @param {LH.Gatherer.Simulation.GraphNode} graph
76
- * @return {Set<string>}
77
- */
78
- static getURLsFailedToPreload(graph) {
79
- // TODO: add `fromPrefetchCache` to Lantern.Types.NetworkRequest, then use node.request here instead of rawRequest.
80
- /** @type {Array<LH.Artifacts.NetworkRequest>} */
81
- const requests = [];
82
- graph.traverse(node => node.type === 'network' && requests.push(node.rawRequest));
83
-
84
- const preloadRequests = requests.filter(req => req.isLinkPreload);
85
- const preloadURLsByFrame = new Map();
86
- for (const request of preloadRequests) {
87
- const preloadURLs = preloadURLsByFrame.get(request.frameId) || new Set();
88
- preloadURLs.add(request.url);
89
- preloadURLsByFrame.set(request.frameId, preloadURLs);
90
- }
91
-
92
- // A failed preload attempt will manifest as a URL that was requested twice within the same frame.
93
- // Once with `isLinkPreload` AND again without `isLinkPreload` but not hitting the cache.
94
- const duplicateRequestsAfterPreload = requests.filter(request => {
95
- const preloadURLsForFrame = preloadURLsByFrame.get(request.frameId);
96
- if (!preloadURLsForFrame) return false;
97
- if (!preloadURLsForFrame.has(request.url)) return false;
98
- const fromCache = request.fromDiskCache ||
99
- request.fromMemoryCache ||
100
- request.fromPrefetchCache;
101
- return !fromCache && !request.isLinkPreload;
102
- });
103
-
104
- return new Set(duplicateRequestsAfterPreload.map(req => req.url));
105
- }
106
-
107
- /**
108
- * We want to preload all first party critical requests at depth 2.
109
- * Third party requests can be tricky to know the URL ahead of time.
110
- * Critical requests at depth 1 would already be identified by the browser for preloading.
111
- * Critical requests deeper than depth 2 are more likely to be a case-by-case basis such that it
112
- * would be a little risky to recommend blindly.
113
- *
114
- * @param {Lantern.Types.NetworkRequest} request
115
- * @param {Lantern.Types.NetworkRequest} mainResource
116
- * @param {Array<LH.Gatherer.Simulation.GraphNode>} initiatorPath
117
- * @return {boolean}
118
- */
119
- static shouldPreloadRequest(request, mainResource, initiatorPath) {
120
- const mainResourceDepth = mainResource.redirects ? mainResource.redirects.length : 0;
121
-
122
- // If it's already preloaded, no need to recommend it.
123
- if (request.isLinkPreload) return false;
124
- // It's not critical, don't recommend it.
125
- if (!CriticalRequestChains.isCritical(request, mainResource)) return false;
126
- // It's not a request loaded over the network, don't recommend it.
127
- if (NetworkRequest.isNonNetworkRequest(request)) return false;
128
- // It's not at the right depth, don't recommend it.
129
- if (initiatorPath.length !== mainResourceDepth + 2) return false;
130
- // It's not a request for the main frame, it wouldn't get reused even if you did preload it.
131
- if (request.frameId !== mainResource.frameId) return false;
132
- // We survived everything else, just check that it's a first party request.
133
- return UrlUtils.rootDomainsMatch(request.url, mainResource.url);
134
- }
135
-
136
- /**
137
- * Computes the estimated effect of preloading all the resources.
138
- * @param {Set<string>} urls The array of byte savings results per resource
139
- * @param {LH.Gatherer.Simulation.GraphNode} graph
140
- * @param {LH.Gatherer.Simulation.Simulator} simulator
141
- * @return {{wastedMs: number, results: Array<{url: string, wastedMs: number}>}}
142
- */
143
- static computeWasteWithGraph(urls, graph, simulator) {
144
- if (!urls.size) {
145
- return {wastedMs: 0, results: []};
146
- }
147
-
148
- // Preload changes the ordering of requests, simulate the original graph
149
- // to have a reasonable baseline for comparison.
150
- const simulationBeforeChanges = simulator.simulate(graph);
151
- const modifiedGraph = graph.cloneWithRelationships();
152
-
153
- /** @type {Array<LH.Gatherer.Simulation.GraphNetworkNode>} */
154
- const nodesToPreload = [];
155
- /** @type {LH.Gatherer.Simulation.GraphNode|null} */
156
- let mainDocumentNode = null;
157
- modifiedGraph.traverse(node => {
158
- if (node.type !== 'network') return;
159
-
160
- if (node.isMainDocument()) {
161
- mainDocumentNode = node;
162
- } else if (node.request && urls.has(node.request.url)) {
163
- nodesToPreload.push(node);
164
- }
165
- });
166
-
167
- if (!mainDocumentNode) {
168
- // Should always find the main document node
169
- throw new Error('Could not find main document node');
170
- }
171
-
172
- // Preload has the effect of moving the resource's only dependency to the main HTML document
173
- // Remove all dependencies of the nodes
174
- for (const node of nodesToPreload) {
175
- node.removeAllDependencies();
176
- node.addDependency(mainDocumentNode);
177
- }
178
-
179
- // Once we've modified the dependencies, simulate the new graph.
180
- const simulationAfterChanges = simulator.simulate(modifiedGraph);
181
- const originalNodesByRequest = Array.from(simulationBeforeChanges.nodeTimings.keys())
182
- // @ts-expect-error we don't care if all nodes without a request collect on `undefined`
183
- .reduce((map, node) => map.set(node.request, node), new Map());
184
-
185
- const results = [];
186
- for (const node of nodesToPreload) {
187
- const originalNode = originalNodesByRequest.get(node.request);
188
- const timingAfter = simulationAfterChanges.nodeTimings.get(node);
189
- const timingBefore = simulationBeforeChanges.nodeTimings.get(originalNode);
190
- if (!timingBefore || !timingAfter) throw new Error('Missing preload node');
191
-
192
- const wastedMs = Math.round(timingBefore.endTime - timingAfter.endTime);
193
- if (wastedMs < THRESHOLD_IN_MS) continue;
194
- results.push({url: node.request.url, wastedMs});
195
- }
196
-
197
- if (!results.length) {
198
- return {wastedMs: 0, results};
199
- }
200
-
201
- return {
202
- // Preload won't necessarily impact the deepest chain/overall time
203
- // We'll use the maximum endTime improvement for now
204
- wastedMs: Math.max(...results.map(item => item.wastedMs)),
205
- results,
206
- };
207
- }
208
-
209
- /**
210
- * @param {LH.Artifacts} artifacts
211
- * @param {LH.Audit.Context} context
212
- * @return {Promise<LH.Audit.Product>}
213
- */
214
- static async audit(artifacts, context) {
215
- const settings = context.settings;
216
- const trace = artifacts.Trace;
217
- const devtoolsLog = artifacts.DevtoolsLog;
218
- const {URL, SourceMaps} = artifacts;
219
- const simulatorOptions = {devtoolsLog, settings: context.settings};
220
-
221
- const [mainResource, graph, simulator] = await Promise.all([
222
- MainResource.request({devtoolsLog, URL}, context),
223
- PageDependencyGraph.request(
224
- {settings, trace, devtoolsLog, URL, SourceMaps, fromTrace: false}, context),
225
- LoadSimulator.request(simulatorOptions, context),
226
- ]);
227
-
228
- const urls = UsesRelPreloadAudit.getURLsToPreload(mainResource, graph);
229
- const {results, wastedMs} = UsesRelPreloadAudit.computeWasteWithGraph(urls, graph, simulator);
230
- // sort results by wastedTime DESC
231
- results.sort((a, b) => b.wastedMs - a.wastedMs);
232
-
233
- /** @type {Array<LH.IcuMessage>|undefined} */
234
- let warnings;
235
- const failedURLs = UsesRelPreloadAudit.getURLsFailedToPreload(graph);
236
- if (failedURLs.size) {
237
- warnings = Array.from(failedURLs)
238
- .map(preloadURL => str_(UIStrings.crossoriginWarning, {preloadURL}));
239
- }
240
-
241
- /** @type {LH.Audit.Details.Opportunity['headings']} */
242
- const headings = [
243
- {key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
244
- {key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnWastedMs)},
245
- ];
246
- const details = Audit.makeOpportunityDetails(headings, results,
247
- {overallSavingsMs: wastedMs, sortedBy: ['wastedMs']});
248
-
249
- return {
250
- score: results.length ? 0 : 1,
251
- numericValue: wastedMs,
252
- numericUnit: 'millisecond',
253
- displayValue: wastedMs ?
254
- str_(i18n.UIStrings.displayValueMsSavings, {wastedMs}) :
255
- '',
256
- details,
257
- warnings,
258
- };
259
- }
260
- }
261
-
262
- export default UsesRelPreloadAudit;
263
- export {UIStrings};