To minify and compress CSS and JavaScript files at a Linux/Unix shell prompt, you can use the following tools:
For CSS files:
- CSSMin: A simple command line tool to minify CSS files. To install it, run the following command:
npm install -g cssmin
To minify a CSS file, run the following command:
cssmin input.css > output.min.css
- YUI Compressor: Another popular command line tool to minify CSS files. To install it, run the following command:
wget https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar
To minify a CSS file, run the following command:
java -jar yuicompressor-2.4.8.jar input.css -o output.min.css
For JavaScript files:
- UglifyJS: A JavaScript parser, minifier, compressor and beautifier toolkit. To install it, run the following command:
npm install -g uglify-js
To minify a JavaScript file, run the following command:
uglifyjs input.js -o output.min.js
- Closure Compiler: A JavaScript optimizer developed by Google. To install it, run the following command:
wget https://dl.google.com/closure-compiler/compiler-latest.zip
unzip compiler-latest.zip
To minify a JavaScript file, run the following command:
java -jar closure-compiler.jar --js input.js --js_output_file output.min.js
Here is an example of how to minify and compress a file called style.css
:
cleancss style.css > style.min.css
And here is an example of how to minify and compress a file called script.js
:
uglifyjs script.js -o script.min.js
Note: You may need to install the uglifyjs
and cleancss
packages first using a package manager like npm
or yarn
.