mix francis.digest (Francis v0.4.0)

View Source

Digests and compresses static files for production deployment.

This task generates versions of static files with content-based hashes in their filenames and creates a manifest file mapping original names to their hashed versions.

$ mix francis.digest
$ mix francis.digest priv/static
$ mix francis.digest priv/static --output priv/static

Command line options

  • --output - the output path for generated files. Defaults to the input path.

  • --age - sets the cache control max age in seconds for static assets. Stored in the manifest as "cache_control" => "public, max-age=<age>, immutable" and exposed through Francis.Static.cache_control/1. Defaults to 31536000 (1 year).

  • --gzip - when set to false, does not generate gzipped files. Defaults to true.

  • --exclude - list of file patterns to exclude from digest. Example: --exclude '*.txt' --exclude '*.json'

  • --clean - removes previously digested files and the manifest before regenerating. Uses the existing manifest to identify files to delete, so only known digested files are removed. Useful for single-instance deploys where stale hashed files are never needed. Avoid in rolling/blue-green deployments where old instances may still serve previous asset hashes.

The output will be a set of digested files along with a cache manifest file. The manifest file maps original file names to their digested counterparts.

Running the task again is safe: the manifest at the output root, the files it lists (digested and gzipped) and, when the output directory lives inside the input directory, everything under the output directory are never digested again. Digested files dropped from the manifest by a later run are treated as sources; use --clean to remove them.

Examples

$ mix francis.digest
Generated digested assets in priv/static:
  * app.css -> app-a1b2c3d4e5f6.css
  * app.js -> app-9f8e7d6c5b4a.js
  * manifest.json

$ mix francis.digest assets --output priv/static
Generated digested assets from assets to priv/static

$ mix francis.digest priv/static --clean
Cleaned 4 previously digested files
Generated digested assets in priv/static

Summary

Functions

Callback implementation for Mix.Task.run/1.

Functions

run(args)

Callback implementation for Mix.Task.run/1.