How to check the size of a gzipped file

Gzipping means compressing a file on your server and sending it down the wire in the compressed .gzip format. The browser then unzips it and serves the uncompressed file on the fly. As Chris Ferdinandi says, it reduces the size of your files by, on average, 70 percent. That’s huge!

I was recently working on an HTML file that totalled 52.2 KB including inline CSS. I wanted to check the gzipped size locally since I didn’t have it up on a server yet. After some searching, I found the following command for Unix-like operating systems:

gzip -c filename.html | wc -c

As much as I hate the toxic community on Stack Overflow, I must give credit to the following page: How can I estimate the size of my gzipped script?

The gzip command does the actual compression. Meanwhile:

In short: the entire command compresses the file on the fly, without affecting the original, and prints the size of the compressed file, in bytes, to the console.

After running it for my 52.2KB file, I saw 8224 in the console. There are 1000 bytes in a kilobyte, so dividing 8224 by 1000 meant that my gzipped file size was 8.2 KB. This is exactly what I was hoping for, since under 14 KB meant I could serve the entire page in a single HTTP request 😁


If you have questions, feedback, or any other suggestions, please do email me. I'd love to hear from you!