Minify and Compress CSS & Javascript Files At a Linux/Unix Shell Prompt

Minify and Compress CSS & Javascript Files At a Linux/Unix Shell Prompt

There are a number of tools available that can minify and compress CSS and JavaScript files at the command line in Linux and Unix systems. Here are a few options:

  1. Use the uglifyjs command: uglifyjs is a JavaScript minification and compression tool that can be used at the command line. To use uglifyjs, you will need to install it first. On a Debian-based system, you can use the following command:
ref‮re‬ to:lautturi.com
sudo apt-get install uglify-js

Once uglifyjs is installed, you can minify a JavaScript file by running the following command:

uglifyjs input.js -o output.min.js

This will minify the input.js file and write the minified version to output.min.js.

  1. Use the cssnano command: cssnano is a CSS minification and compression tool that can be used at the command line. To use cssnano, you will need to install it first. On a Debian-based system, you can use the following command:
sudo apt-get install cssnano

Once cssnano is installed, you can minify a CSS file by running the following command:

cssnano input.css > output.min.css

This will minify the input.css file and write the minified version to output.min.css.

  1. Use the gzip command: gzip is a file compression tool that can be used at the command line to compress files in the gzip format. To use gzip, you can run the following command:
gzip input.js

This will compress the input.js file and create a new file called input.js.gz. To uncompress the file, you can use the gunzip command:

gunzip input.js.gz

Keep in mind that minifying and compressing CSS and JavaScript files can help reduce the size of your web pages and improve the performance of your website. However, it's important to test the performance of your website with and without minification and compression to determine whether it is beneficial in your specific case.

Created Time:2017-10-30 10:17:50  Author:lautturi