|
| 1 | +// Copyright 2025 The Chromium Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +import * as i18n from '../../../core/i18n/i18n.js'; |
| 6 | +import type * as Types from '../types/types.js'; |
| 7 | + |
| 8 | +import {InsightCategory, type InsightModel, type InsightSetContext, type RequiredData} from './types.js'; |
| 9 | + |
| 10 | +const UIStrings = { |
| 11 | + /** |
| 12 | + * @description Title of an insight that recommends avoiding chaining critical requests. |
| 13 | + */ |
| 14 | + title: 'Long critical network tree', |
| 15 | + /** |
| 16 | + * @description Description of an insight that recommends avoiding chaining critical requests. |
| 17 | + */ |
| 18 | + description: |
| 19 | + '[Avoid chaining critical requests](https://developer.chrome.com/docs/lighthouse/performance/critical-request-chains) by reducing the length of chains, reducing the download size of resources, or deferring the download of unnecessary resources to improve page load.', |
| 20 | +}; |
| 21 | + |
| 22 | +const str_ = i18n.i18n.registerUIStrings('models/trace/insights/LongCriticalNetworkTree.ts', UIStrings); |
| 23 | +const i18nString = i18n.i18n.getLocalizedString.bind(undefined, str_); |
| 24 | + |
| 25 | +export type LongCriticalNetworkTreeInsightModel = InsightModel<{ |
| 26 | + longChains: Types.Events.SyntheticNetworkRequest[][], |
| 27 | +}>; |
| 28 | + |
| 29 | +export function deps(): ['NetworkRequests'] { |
| 30 | + return ['NetworkRequests']; |
| 31 | +} |
| 32 | + |
| 33 | +function finalize( |
| 34 | + partialModel: Omit<LongCriticalNetworkTreeInsightModel, 'title'|'description'|'category'|'shouldShow'>): |
| 35 | + LongCriticalNetworkTreeInsightModel { |
| 36 | + return { |
| 37 | + title: i18nString(UIStrings.title), |
| 38 | + description: i18nString(UIStrings.description), |
| 39 | + category: InsightCategory.LCP, |
| 40 | + shouldShow: partialModel.longChains.length > 0, |
| 41 | + ...partialModel, |
| 42 | + }; |
| 43 | +} |
| 44 | + |
| 45 | +export function generateInsight( |
| 46 | + _parsedTrace: RequiredData<typeof deps>, _context: InsightSetContext): LongCriticalNetworkTreeInsightModel { |
| 47 | + return finalize({ |
| 48 | + longChains: [], |
| 49 | + }); |
| 50 | +} |
0 commit comments