← All Exercises

Check an Initial Bundle Against Budget

basicjavascript~20min

Background

Performance regressions arrive as quiet bundle growth. A budget check in CI makes the cost of a new dependency visible before it reaches users.

Problem

Sum the sizes of initial chunks, compare them with the budget, and report the largest chunk that dominates the payload.

Input

JSON object: { chunks: [{ name, sizeKb, initial }], budgetKb }

Output

JSON object: { initialKb, overBudget, largestChunk }

Sample tests

Sample 1

Input: {"chunks":[{"name":"main","sizeKb":120,"initial":true},{"name":"vendor","sizeKb":80,"initial":true},{"name":"settings","sizeKb":40,"initial":false}],"budgetKb":150}
Expected: {"initialKb":200,"overBudget":true,"largestChunk":"main"}

Sample 2

Input: {"chunks":[{"name":"main","sizeKb":90,"initial":true}],"budgetKb":150}
Expected: {"initialKb":90,"overBudget":false,"largestChunk":"main"}

Your solution

Learning objective

Keep the first-load payload inside an explicit budget.