Why
I'm a lazy person. I've never done zip compression for responses to clients (although I've used encryption to reduce content size before sending). When someone recommended that I should zip and send it back to clients, it raised the question: "Hey, is what we've been using all along (HTTP compression) better? Or is manual zip better?". This project was born to compare data transmission between HTTP compression and manual ZIP response.
What
This project will be divided into 3 main parts:
- Compression Server: Uses Express with compression middleware to send data compressed with gzip
- Manual ZIP Server: Uses Express with middleware to create ZIP files with the returned data
- Client: Calls both APIs and compares data transmission sizes. It will test both HTTP compression and manual ZIP. For HTTP compression, it will test all four types (gzip, deflate, br, and all) to see how their performance compares.
How
From the code in https://github.com/ilumin/http-compression-vs-manual-zip
Start the compression server and manual ZIP server waiting for the client to make a request.
The client will make 5 requests
- HTTP Compression (All)
- HTTP Compression (Gzip)
- HTTP Compression (Deflate)
- HTTP Compression (Brotli)
- and manual ZIP
And compare responses with transfer size.
Result
Method Transfer Size Compression Ratio Duration
--------------------------------------------------------------------------------
HTTP Compression (All) 113,521 bytes 96.65% 29ms
HTTP Compression (Gzip) 133,235 bytes 96.07% 39ms
HTTP Compression (Deflate) 133,184 bytes 96.07% 37ms
HTTP Compression (Brotli) 114,375 bytes 96.63% 23ms
Manual ZIP 141,117 bytes N/A% 70ms
Best compression: HTTP Compression (All) with 113,521 bytes
- HTTP Compression (All) (the server will automatically choose which compression method to use) can perform better than manual zip
- With the same compression method (Deflate), HTTP Compression can still perform better with shorter processing time
- Looking at the figures, they're not very different, but the effort, limitations, and risks of doing Manual ZIP are greater than HTTP Compression
Conclusion
Ask yourself why you want to reinvent the wheel when you already have Tesla.
Note:
- In the code, I used a native HTTP client because I don't know how to intercept and get the transfer size from Axios since it automatically decompresses everything
- Modern frameworks nowadays have built-in HTTP compression, so much so that we forget this kind of thing exists in the world