Minify css files in linux shell

Minify css files in linux shell

Posted by

Yesterday morning, I have few hours to work on my blog and I  decided to spend some time optimising my website load time. It is a bit tricky but should pay it in terms of Google traffic. So, to check the website speed, I am using the best tool ever! It is made by Google experts. It is called Google Page Speed available here: https://developers.google.com/speed/pagespeed/insights/

After some time optimising my website I got to 97% for the Desktop, which I consider pretty good.

Minify css files in linux shell

As one of the steps, I had to combine and minify CSS files. For this, I used one of the free Python libraries called cssmin. I manage to run it in the shell. I installed Python cssmin using the following command:


pip install rcssmin

Here is a basic command to minify the CSS files:

python -c 'from rcssmin import cssmin; print cssmin(open("style.css","r").read())'

This is the final version of the command I used:

mv style.css style-original.css
python -c 'from rcssmin import cssmin; print cssmin(open("style-original.css","r").read())' > style.css

I hope you find this useful.