How can I estimate the size of my JavaScript file after it is gzipped? Are there online tools for this? Or is it similar to using winzip for example?
"gzip" is often also used to refer to the gzip file format, which is: a 10-byte header, containing a magic number ( 1f 8b ), the compression method ( 08 for DEFLATE), 1-byte of header flags, a 4-byte timestamp, compression flags and the operating system ID.
Gzip, the most popular compression method, is used by web servers and browsers to seamlessly compress and decompress content as it's transmitted over the Internet. Used mostly on code and text files, gzip can reduce the size of JavaScript, CSS, and HTML files by up to 90%.
There is no way to directly determine gzip level . The only way to determine it in my opinion is to gunzip the file and compressing it at different levels and then comparing the results with your existing file size.
gzip uses the Lempel–Ziv algorithm used in zip and PKZIP . The amount of compression obtained depends on the size of the input and the distribution of common substrings. Typically, text such as source code or English is reduced by 60–70%.
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:
gzip -c "$f" | wc -c
and wc -c "$f"
Cygwin contains command line implementations of gzip
and wc
for Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With