Skip to content
jshacks.dev
Packages

Compare package sizes with bundlephobia data

Fetch minified and gzipped sizes for two packages from the Bundlephobia API in a short Node.js script before you pick one. Node 24 and its built-in fetch.

1 min read
Summarize in AI

Choosing between two date libraries? Bundlephobia calculates what a package adds to a bundle, and its API returns JSON. Node.js 24 has fetch built in, so a script needs no dependency.

compare.mjsJavaScript
const pkgs = ["[email protected]", "[email protected]"];
for (const p of pkgs) {
  const res = await fetch(`https://bundlephobia.com/api/size?package=${p}`);
  const { name, version, size, gzip } = await res.json();
  console.log(`${name}@${version} min=${size} gzip=${gzip}`);
}
Text
[email protected] min=<bytes> gzip=<bytes>
[email protected] min=<bytes> gzip=<bytes>

Each <bytes> stands for the number the API returns when you run it; the figures change per release, so this page does not print them. size is the minified size and gzip the compressed size, per the Bundlephobia site.

It measures the package bundled whole, and does not know what you import. A tree-shakeable library you import one function from costs far less than the number shown. Use it to compare, and measure your real bundle with your bundler's analyzer before deciding.

The service rate-limits automated requests, so avoid calling it in a loop in CI.

Also inTooling
Share

More snippets

Packages

Initialize a package with npm init

Initialize a package.json with npm init, skip the questions with the yes flag, and set your own defaults for author and license in npm config.

1 min read
Tooling

Create a Vite project from a template

Create a Vite project from a template with npm create vite, choose the vanilla-ts or react-ts template and see which files it generates.

1 min read
Packages

Generate a changelog from commits

Turn conventional commit messages into a CHANGELOG.md section with conventional-changelog, grouped by feature and fix. Works with any Git history.

1 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.