8 releases

0.3.0 May 2, 2024
0.2.3 Jun 9, 2023
0.2.2 Dec 19, 2022
0.2.1 Jul 23, 2022
0.1.2 Jul 21, 2022

#420 in Command line utilities

Download history 31/week @ 2024-02-23 15/week @ 2024-03-01 18/week @ 2024-03-08 5/week @ 2024-03-15 7/week @ 2024-03-29 134/week @ 2024-04-26 38/week @ 2024-05-03

172 downloads per month

MIT license

546 lines


Precompress a directory of assets

precompress will recursively compress all suitable assets in a given directory, creating (or replacing) compressed versions of the original files using the appropriate extension type (e.g. gzip: index.html -> index.html.gz).


Using cargo:

cargo install precompress


> precompress --help
Precompress a directory of assets

Usage: precompress [OPTIONS] <PATH>

  <PATH>  Directory to recursively compress files in

  -c, --compression <COMPRESSION>  Compression algorithms to use
  -e, --extensions <EXTENSIONS>    Extensions of files that should be compressed
  -m, --min-size <MIN_SIZE>        Set the minimum size of files to be compressed in bytes [default: 1024]
  -t, --threads <THREADS>          Number of threads to use; "0" uses the number of cpus [default: 0]
  -h, --help                       Print help
  -V, --version                    Print version

By default, all compression algorithms are enabled. To specify the specific types of compression you want to enable, you can use the -c flag with the values:

  • br or brotli
  • de or deflate
  • gz or gzip
  • zstd

The compression quality can be specified by adding the value after a colon:

precompress -c gzip:5 .

There are number of file extensions that are compressed by default. To sepcify the specific extensions to compress, you can use the -e flag like so:

precompress -e css -e json -e html .


precompress -e css,json,html .


Precompress the html files in the current directory using brotli and gzip with a quality of 5, and a minimum file size of 4096:

precompress -c br:5,gz:5 -e html -m 4096 .


precompress -c br:5 -c gz:5 -e html -m 4096 .


precompress is released under the MIT license. Please see the LICENSE file for more details.


~549K SLoC