npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2024 – Pkg Stats / Ryan Hefner

@rviscomi/capo.js

v1.5.2

Published

Get your οΉ€πš‘πšŽπšŠπšοΉ₯ in order

Downloads

154

Readme

rviscomi/capo.js

Get your <head> in order

Inspired by Harry Roberts' work on ct.css and Vitaly Friedman's Nordic.js 2022 presentation:

image

Why it matters

How you order elements in the <head> can have an effect on the (perceived) performance of the page.

This script helps you identify which elements are out of order.

How to use it

✨ New: Install the Capo Chrome extension ✨

  1. Copy capo.js
  2. Run it in a new DevTools snippet, or use a bookmarklet generator
  3. Explore the console logs

For applications that add lots of dynamic content to the <head> on the client, it'd be more accurate to look at the server-rendered <head> instead.

Chrome extension

Capo.js Chrome extension

WIP see crx/

WebPageTest

You can use the capo WebPageTest custom metric to evaluate only the server-rendered HTML <head>. Note that because this approach doesn't output to the console, we lose the visualization.

BigQuery

You can also use the httparchive.fn.CAPO function on BigQuery to process HTML response bodies in the HTTP Archive dataset. Similar to the WebPageTest approach, the output is very basic.

Other

Alternatively, you can use local overrides in DevTools to manually inject the capo.js script into the document so that it runs before anything else, eg the first child of <body>. Harry Roberts also has a nifty video showing how to use this feature. This has some drawbacks as well, for example the inline script might be blocked by CSP.

Another idea would be to use something like Cloudflare workers to inject the script into the HTML stream. To work around CSP issues, you can write the worker in such a way that it parses out the correct nonce and adds it to the inline script. (Note: Not tested, but please share examples if you get it working! πŸ˜„)

Summary view

The script logs two info groups to the console: the actual order of the <head>, and the optimal order. In this collapsed view, you can see at a glance whether there are any high impact elements out of order.

Each "weight" has a corresponding color, with red being the highest and blue/grey being the lowest. See capo.js for the exact mapping.

Here are a few examples.

www.nytimes.com

docs.github.io

web.dev

stackoverflow.com

Detailed view

Expanding the actual or sorted views reveals the detailed view. This includes an itemized list of each <head> element and its weight as well as a reference to the actual or sorted <head> element.

www.nytimes.com

Here you can see a drilled-down view of the end of the <head> for the NYT site, where high impact origin trial meta elements are set too late.