How can I estimate the size of my gzipped script?

How can I estimate the size of my javascript file after it is gzipped? Are there online tools for this? Or is it like using winzip for example?

+69
javascript gzip minify
Feb 27 '12 at 16:29
source share
8 answers

http://closure-compiler.appspot.com/home allows you to embed code, and it will give you compression ratios for a specific 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 options to evaluate the compression of non-minified content.

If you need a grade:

  • Start with 100 JS files that have passed the same minification protocol.
  • For each file, calculate the size relationship between gzip -c "$f" | wc -c gzip -c "$f" | wc -c and wc -c "$f"
  • The average value of these coefficients is the approximate compression value that should be expected for a similar JS file.

Cygwin contains gzip and wc command line versions for Windows.

+46
Feb 27 2018-12-12T00:
source share

If you are using unix - gzip -c filename.min.js | wc -c gzip -c filename.min.js | wc -c , you will get the number of bytes of the gzipped file

+99
Feb 27 '12 at 16:34
source share

7-zip supports compression to the GZIP format.

I often use this to approximate and compare file sizes.

When creating an archive, look for the Archive Format , and gzip is the third option.

Update:

In the comments, we discussed that there may be a difference between GZIP 7-zip compression and actual GZIP server compression. So, I compared using only the homepage http://www.google.com/ .
The Google GZIP payload was 36,678 bytes. The 7-zip with the "gzip Normal" setting was 35,559 (3% less). When setting up "gzip Fastest", it amounted to 37,673 (3% more).

So, a short story: 7-zip had results with an accuracy of about 97% .

+9
Oct 18 '13 at 22:03
source share

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 contentison,

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

To get it programmatically, there are utilities such as gzip-size . This is a node package, but you can install it globally as a general tool.

+8
Jun 10 '15 at 8:11
source share

http://refresh-sf.com/ will give you the coefficients and sizes of minification and gzip.

+7
Jul 16 '14 at 22:28
source share

If you want to compare the uncompressed, compressed, and compressed file sizes for the entire folder: (assuming you want to filter *.js ):

 for file in *.js; do printf "$file\t$(cat $file | wc -c)\t$(gzip -kc7 $file | wc -c)\t$(brotli --in $file --out temp.br --force --quality 11 && cat temp.br | wc -c)\n"; done | tee filesizes.log 

Sample output (separated by tabs so you can copy to a spreadsheet):

 foo.js 39035 10150 8982 bar.js 217000 68978 56337 
+1
Dec 20 '18 at 14:44
source share

You can install gzip yourself on Windows through Gow (Gnu On Windows) .

0
Mar 28 '15 at 13:38
source share

With the host kernel, you can use the length of the zlib.gzip buffer to determine the size of gzip:

 const fs = require('fs'); const util = require('util'); const zlib = require('zlib'); const readFile = util.promisify(fs.readFile); const gzip = util.promisify(zlib.gzip); const getGzipSize = filePath => readFile(filePath) .then(gzip) .then(x => x.length); 
0
Aug 19 '19 at 12:45
source share



All Articles