How can I estimate the size of my gzipped script? How can I estimate the size of my gzipped script? javascript javascript

How can I estimate the size of my gzipped script?


If you're on unix - gzip -c filename.min.js | wc -c will give you a byte count of the gzipped file


http://closure-compiler.appspot.com/home lets you paste in code, and it will give you compression ratios for a particular file before and after GZIP.

Original Size:    90 bytes (100 bytes gzipped)Compiled Size:    55 bytes (68 bytes gzipped)Saved 38.89% off the original size (32.00% off the gzipped size)

You can use the pretty-print and white-space only options to estimate the compression of non-minified content.

If you need an estimate:

  • Start with 100 JS files that have gone through the same minification pipeline.
  • For each file, compute the ratio in sizes between gzip -c "$f" | wc -c and wc -c "$f"
  • The average of those ratios is an approximation of the compression you should expect for a similar JS file.

Cygwin contains command line implementations of gzip and wc for Windows.


Directly from the terminal,

gzip -9 -c path/to/file.js | wc -c | numfmt --to=iec-i --suffix=B --padding=10

If you need the original size for comprison,

cat path/to/file.js | wc -c | numfmt --to=iec-i --suffix=B --padding=10

To get it programatically there are utilities like gzip-size. It's a node package but you can install it globally as a general tool.