Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Zopfli for gzip compression #2998

Open
lrussell887 opened this issue Nov 5, 2024 · 0 comments
Open

Use Zopfli for gzip compression #2998

lrussell887 opened this issue Nov 5, 2024 · 0 comments

Comments

@lrussell887
Copy link

I've noticed that this project is using standard gzip with level 9 compression in the scripts/dist.sh script. If Google's Zopfli compression algorithm were used instead, the minified gzip file could be made even smaller.

This can most easily be done with 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 which goes into more detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants