← 中文资源

简体中文版本

性能预算强制工作流

定义并强制执行页面体积、加载时间和运行时指标的性能预算,防止性能退化。

阅读英文原文

概述

性能预算强制工作流是一个中级难度的工作流。定义并强制执行页面体积、加载时间和运行时指标的性能预算,防止性能退化。该工作流的目标是:Establish and enforce performance budgets to prevent regressions.

环境准备

执行本工作流需要以下环境:A web application with performance monitoring;Lighthouse or WebPageTest for measurement;CI pipeline for enforcement。请确保在开始前准备好所有必需的工具和资源,以避免中途因环境问题中断。

执行步骤

本工作流包含5个步骤。步骤1:Define budgets——Set performance budgets for JavaScript size, image size, LCP, and CLS. 步骤2:Measure baseline——Run Lighthouse to measure current performance and compare against budgets. 步骤3:Add CI check——Add a Lighthouse CI step that fails if any budget is exceeded. 步骤4:Fix violations——Address any current budget violations before enabling the CI gate. 步骤5:Monitor trends——Set up monitoring to track performance trends over time.

验证与清理

预期结果:Performance budgets are defined, enforced in CI, and monitored for trends.。验证方法:Run Lighthouse in CI and confirm the build fails if a budget is exceeded; verify current metrics are within budget.。清理操作:Temporarily relax budgets if a critical feature requires it; track the debt and tighten budgets later.。estimatedMinutes 为 45 分钟。

代码示例

# Execute the workflow steps as documented above
echo "Workflow completed successfully"