Minify css files in linux shell

Yesterday morning, I have few hours to work on my blog and I  decided to spend some time optimizing 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 optimizing my website I got to 97% for the Desktop, which I consider pretty good.

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.

About the author

Yuli Stremovsky
Yuli StremovskyKesem.IO CTO
Yuli is experienced software security architect, is a co-founder of Kesem.IO, working as a company CTO.
KESEM.IO is creating a trusted, fast, secure and easy to use solution to guarantee mobile payments on blockchain enabled digital assets.
Before Kesem.IO, Yuli was a founder of a database security company GreenSQL/Hexatier which was acquired by Huawei.

Some my code is available at:
https://github.com/stremovsky
https://github.com/kesem-io