Web perf basics - Performance Budgets
Web perf basics - Performance Budgets
Climbing the performance ladder requires hard work, learn how to prevent regressions and enjoy the view.
Resource & metric based budgets
Now that we’ve talked about performance metrics and introduced ourselves to SpeedCurve, I would like to continue with performance budgets and the role they play when building performant web experiences.
Performance budgets are made up of two things, resource budgets - limiting asset file size, and metric budgets - monitoring Synthetic & RUM data and the many many metric acronyms that belong to that segment.
Let’s begin on the more uncomplicated side and talk about resource budgets first. Resource budgets are simply file-size constraints on normally all of your resources, like the HTML document, your CSS, your fonts, your images, JavaScript, and so on.
Resource budgets
To define a resource budget, ask yourself the question:
What's important for my site to be able to perform, to be valuable?
Odds are pretty high you may need to cut down on a few things to reach your set target, and you might be surprised that cutting down doesn’t need to be a bad thing.
If you don’t know where to begin there are many resources out there that can assist you in the process of creating your own resource budget, and a favorite one of mine is the site performancebudget.io
Their idea is simple - you create your budget simply by filling in the blanks in the following sentence:
I want my site to load in [ X ] seconds, on a [ X ] connection
The generated budget is purely a result of full resource load vs connection speed, so to reach the goal of loading a site in 5 seconds on a Fast 3G mobile connection (1.6 Mbps), your budget would look something like this:
HTML - 25kb | CSS - 32kb | JavaScript - 165kb | Images - 630kb Video - 97kb | Fonts - 50kb
Total budget: 999kb
Now let's look at a full load in 5 seconds but on a slower 3G connection (780 Kbps)
HTML - 12kb | CSS - 15kb | JavaScript - 79kb | Images - 302kb Video - 46kb | Fonts - 24kb
Total budget: 478kb
The numbers paint a pretty clear picture - images and scripts are seemingly our largest resources and thus our biggest problem area.
And although the "reduce one, increase the other" mindset does work, remember that it's generally considered a bad thing to increase on the script side due to its blocking (parsing, compiling, and execution) nature.
So what's a good resource budget?
Well, it depends entirely on your application. While keeping Javascript to a minimum is sought after in an e-commerce context where speed equals money, you might actually be working on something that resembles more of an app than anything else. And in that case, your budget needs to take that into account.
The goal here is not about recommending your client a full rewrite to reach a utopian budget but to play the cards you've been handed and make the best of what you've got.