Skip to content

rhpvorderman/gzip_static

Repository files navigation

image

gzip_static

Compress your static website or website's static assets with gzip for faster serving with nginx's gzip_static module.

Nginx does not perform checks on the served gzip to determine if it is out of date. This program was created to automate the checks and compression of the static files at the website's build time.

Features

  • Finds all static files in a directory and its subdirectories automatically based on an extensions file which can be customized.
  • Idempotent. Only compresses files that have not been compressed yet or are changed. Can therefore be used with configuration management systems such as Ansible.
  • Guards against serving outdated gzips
    • Gzip content is checked with a checksum to verify that a file has changed.
    • Has a --remove-orphans option to remove gzips for which the source static file is no longer available.
  • The created gzip files inherited filesystem attributes from the source static files such as the mode and the last modified time.
  • Works on any machine with Python 3.6 or higher installed. It does not depend on other packages for its core functionally.
  • Zopfli compression is supported when zopfli is installed.
  • Can be used as a library in other projects and has a fully documented API.
  • Optimized for checksumming small gzip file contents. Rerunning gzip_static on an already compressed website is very quick.

Quickstart

Install gzip_static with pip install gzip_static or pip install --user gzip_static. For more installation options and options to enable more functionally such as zopfli and better speed, checkout the installation documentation.

  • To compress all static files in a directory: gzip-static /var/www/my_example_website/
  • To check if all gzip files are up to date and recompress gzip files for which the source has changed: gzip-static /var/www/my_example_website/ (Same command due to idempotency)
  • To check if all gzip files are up to date, recompress changed ones and remove gzip files for which a source static file is no longer present: gzip-static --remove-orphans /var/www/my_example_website/
  • To check for orphaned files only: gzip-static-find-orphans /var/www/my_example_website/

For a more extended usage and more options use gzip-static --help or checkout the usage documentation.

Contributing

For bug reports and feature requests please use the github issue tracker. Pull requests are also welcome.

Please note that brotli support is currently not in this project's scope. This may change. For more information read here.