A lightweight command-line tool designed to simplify and streamline the minification process for CSS and JavaScript files. Minification involves the removal of unnecessary characters and spaces from code, resulting in smaller file sizes that contribute to improved web page loading times.
Get up and running in under 2 minutes:
# Install the tool
go install github.com/Alitindrawan24/go-minifier
# Minify a CSS file
go-minifier -src styles.css
# Minify a JavaScript file
go-minifier -src script.js -opt js- Go 1.19 or later
go install github.com/Alitindrawan24/go-minifierUsing HTTPS:
git clone https://github.com/Alitindrawan24/go-minifier.git
cd go-minifierUsing SSH:
git clone git@github.com:Alitindrawan24/go-minifier.git
cd go-minifierBasic usage - Creates filename.min.css:
go run . -src styles.cssCustom output filename:
go run . -src styles.css -out production.min.cssWorking with multiple CSS files:
# Minify multiple CSS files
go run . -src main.css
go run . -src components.css -out components.min.css
go run . -src responsive.css -out responsive.min.cssBasic usage - Creates filename.min.js:
go run . -src script.js -opt jsCustom output filename:
go run . -src app.js -out app.min.js -opt jsWorking with multiple JavaScript files:
# Minify multiple JS files
go run . -src main.js -opt js
go run . -src utils.js -out utils.min.js -opt js
go run . -src vendor.js -out vendor.min.js -opt js| Option | Description | Required | Default |
|---|---|---|---|
-src |
Path to the source file | ✅ | - |
-out |
Path to the output file | ❌ | filename.min.css/js |
-opt |
Minifier type (css or js) |
❌ | css |
Valid values for -opt:
css- For CSS files (default)js- For JavaScript files
After minification, you'll see file size statistics:
File styles.css original size: 15 KB
File styles.min.css output size: 8 KB (reduced by 46.67%)
make testmake fmtmake lint- Minify all CSS/JS files in a directory
- Batch processing capabilities
- Additional file format support