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.
For example:
dir/
└── index.html
would become:
dir/
├── index.html
├── index.html.br
├── index.html.gz
├── index.html.zst
└── index.html.zz
Using cargo
:
cargo install precompress
Or download a binary from the latest release.
> precompress --help
Precompress a directory of assets
Usage: precompress [OPTIONS] <PATH>
Arguments:
<PATH> Directory to recursively compress files in
Options:
-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
orbrotli
de
ordeflate
gz
orgzip
zst
orzstd
By default, the highest supported compression quality is used for each algorithm. To specify a different quality, add the value after a colon like so:
precompress -c gzip:5 .
There are a number of file extensions that are compressed
by default. To disable that behaviour, you may specify the specific extensions
to compress by using the -e
flag like so:
precompress -e css -e json -e html .
or
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 .
or
precompress -c br:5 -c gz:5 -e html -m 4096 .
Files with the following extensions are compressed by default:
atom
cfg
component
conf
css
csv
eot
geojson
graphql
htm
html
ico
java
js
json
jsx
ldjson
log
manifest
map
md
mjs
otf
rss
rtf
scss
sfnt
sitemap
svg
text
ts
tsv
tsx
ttf
txt
wasm
woff
xhtml
xml
yaml
yml
precompress
is released under the MIT license.
Please see the LICENSE file for more details.