compress_zstd

This script will compress the given file with zstd.

Here is a fragment to be placed into your .htaccess or Apache HTTPD server configuration file:

<IfModule mod_headers.c>
  RewriteCond "%{HTTP:Accept-encoding}" "zstd"
  RewriteCond "%{REQUEST_FILENAME}.zst" -s
  RewriteRule "^(.*)\.(css|html|js|mjs|svg)$" "/$1.$2.zst" [QSA]

  RewriteRule "\.css\.zst$" "-" [T=text/css,E=no-brotli:1,E=no-gzip:1,E=no-zstd:1]
  RewriteRule "\.html\.zst$" "-" [T=text/html,E=no-brotli:1,E=no-gzip:1,E=no-zstd:1]
  RewriteRule "\.js\.zst$" "-" [T=text/javascript,E=no-brotli:1,E=no-gzip:1,E=no-zstd:1]
  RewriteRule "\.mjs\.zst$" "-" [T=text/javascript,E=no-brotli:1,E=no-gzip:1,E=no-zstd:1]
  RewriteRule "\.svg\.zst$" "-" [T=text/javascript,E=no-brotli:1,E=no-gzip:1,E=no-zstd:1]

  <FilesMatch "(\.css|\.html|\.js|\.mjs|\.svg)\.zst$">
    Header append Content-Encoding zstd
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

Usage

$ scripts/web/compress_zstd.sh test.txt
$ find dist \( -type f -name '*.html' -o -name '*.css' \) -exec scripts/web/compress_zstd.sh {} \;

Prerequisites