Capo.js: A five minute web performance boost
You want a quick web performance win at work that’s sure to get you a promotion? Want it to only take five minutes? Then I got you.
Capo.js is a tool to get your <head>
in order. It’s based on some research by Harry Roberts that shows how something seemingly insignificant as the elements in your <head>
tag can make your page load up to 7 seconds slower! From pragma directives, to async scripts, to stylesheets, to open graph tags, it’s easy to mess up and can have consequences. Capo.js will show you the specific order of elements to make your <head>
and your page a little (or a lotta) bit faster.
Usage
- Head over to Capo.js homepage
- Install the Capo.js Chrome Extension (you can also use it as a DevTools Snippet or bookmarklet)
- Run Capo.js
Capo.js will log two colored bar charts in your JS console; your “Actual” <head>
order and a “Sorted” <head>
order. You can expand each chart to see more details. If you see a big gray bar in the middle of your “Actual” bar chart, then you’re leaving some quick wins on the table. The “Sorted” dropdown will show you the corrected order and even give you the code. But in the real world you probably need to futz with a layout template or your _header.php
to get it reorganized.
Installing Capo.js takes about a minute, rearranging your <head>
takes another minute. Honestly the longest part is making the Pull Request.
EDITOR INTERVENTION
[Chris busts through the door.]
OK fine Dave, I’ll give it a shot right here on Boost itself.
I installed the Chrome Extension and ran it and got this little popup:
At first I was a little confused, like this was some fancy code that Web Perf people immediately understand but I was out of the loop on. But actually it’s just a visualization of the order of things (top: actual, bottom: ideal). As a little UX feedback, it should say “Open your console for more information” because that’s where all the useful stuff is.
I found it most useful to look at the “Sorted” output (which is what you should be doing) and then try to get my source code to match that. I think I generally did OK:
I wasn’t able to get it perfect because of WordPress. A decent chunk of what goes into your <head>
in WordPress comes from the output of the <php wp_head(); ?>
function. I’m sure it’s technically possible to re-order output in there, but that was a more effort that I felt was worth it right at this minute.
Take your wins, that’s what I always say.