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.
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.
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}`);
}[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.