Minify & Compress Static Assets
Minify CSS and JS with optional gzip compression and hash-based cache busting.
Asset Minification
Barry lets you minify CSS and JavaScript assets directly from your templates using a built-in template function. This helps reduce file size, enable compression, and bust stale caches automatically.How It Works
When rendering your template, use the minify function:
<link rel="stylesheet" href="{{ "/static/style.css" | minify }}">
<script src="{{ "/static/app.js" | minify }}"></script>
This will generate and serve a version like:
/static/style.min.css?v=45c6d4
Features
- ✅ Only runs in production
- 📁 Minified files saved in
cache/static/ - 💨 Gzip versions automatically created
- 🔁 Hashes added for cache busting
- ✂️ Ignores already-minified files (e.g.
.min.css)
Development Mode
During barry dev, minify returns the original path unmodified for easy debugging.
Notes
The minify function only applies to CSS and JavaScript. Other assets like images or HTML are not modified. Already-minified files like style.min.css will be skipped.