Part 06 · Production · 6.1.10

Performance, tests, bundling và frontend supply chain

Optimize bằng user-centric measurement và shipped artifact; dev bundle, synthetic microbenchmark hay Lighthouse score đơn lẻ không chứng minh production UX.

Measurement rule: profile before optimize, compare representative device/network distributions and connect a change to a user or business outcome.

1. Performance và critical path

Critical rendering path, long tasks, layout/paint, JS parse/execute, memory và network waterfall đều có thể tạo jank. Theo dõi Core Web Vitals/RUM theo device/network; synthetic lab giúp repeatability nhưng không thay field data.

2. Testing strategy

LayerTargetTrade-off
UnitPure logic, type/state transitionsNhanh nhưng không chứng minh DOM/network contract
DOM/componentUser interaction, accessibility role, async stateỔn định hơn implementation-detail selectors
Contract/APIRequest/response/schema compatibilityCần fixture/version ownership
Browser E2ECritical flow và cross-origin behaviorĐắt/chậm; chọn smoke path có giá trị

Fake timers/network có giới hạn; test cancellation, race và cleanup thật ở một số integration layer. Tránh assert private implementation khi hành vi user-facing mới là contract.

3. Build, bundling và source maps

Transpile đổi syntax; bundle resolve module graph; minify đổi representation. ESM static graph hỗ trợ tree shaking, code splitting giảm initial cost nhưng tăng request/cache coordination. Analyze duplicate dependencies, content-hash assets và giữ source-map access private nếu map chứa source nhạy cảm.

source -> typecheck/transpile -> bundle/split -> minify
       -> content-hashed artifact -> immutable deploy/cache

4. Supply chain và delivery

Lockfile/registry integrity, dependency review/audit, install scripts, provenance/SBOM, immutable CI artifact và CSP là một chuỗi. Untrusted PR không nhận publish/deploy secrets; pin action/tool versions và verify artifact trước promote.

Production gate: có performance budget/RUM, test pyramid với critical E2E, bundle diff, dependency/SBOM report, rollback artifact và owner cho source-map/secret exposure.
Tài liệu: web.dev Core Web Vitals · MDN Web Performance · MDN JavaScript Modules