bigskysoftware / bigskysoftware/htmx
Use Zopfli for gzip compression
- Dominant language
- JavaScript
- Stars
- 49.4k
- Forks
- 1.7k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 30
Description
I've noticed that this project is using standard gzip with level 9 compression in the `scripts/dist.sh` script. If Google's [Zopfli](https://developers.googleblog.com/en/compress-data-more-densely-with-zopfli/) compression algorithm were used instead, the minified gzip file could be made even smaller.
This can most easily be done with [pigz](https://zlib.net/pigz/), a drop-in multi-threaded replacement for gzip, which utilizes Zopfli when the compression level is set to 11.
I tested this against the latest 2.0.3 release of `htmx.min.js`:
- gzip -9: 16,180 bytes
- pigz -11: 15,694 bytes
This is a **3% reduction** in file size. The resultant file is fully compatible with existing deflate/gzip -- decompression is unaffected.
Granted, this doesn't come entirely for free, at the expense of compute time:
```
root@server:~# time gzip -9 htmx.min.js
real 0m0.007s
user 0m0.003s
sys 0m0.004s
```
```
root@server:~# time pigz -11 htmx.min.js
real 0m0.146s
user 0m0.146s
sys 0m0.000s
```
Though I would argue the time difference is negligible and worth it, given the compress once, download many paradigm something like this project follows. Saving even just 486 bytes across the wire adds up with enough traffic.
I would definitely recommend reading [this article](https://blog.codinghorror.com/zopfli-optimization-literally-free-bandwidth/) which goes into more detail.
Contributor guide
Assessment
This issue has not been assessed yet.