Minify css files in linux shell

Minify css files in linux shell

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.

About the author

Yuli Stremovsky
Yuli StremovskyParanoid Security Guy
For the past 15 years I’ve been leading the evolution of startups and enterprises to achieve the highest level of security and compliance. Throughout my career I’ve been a Cyber Security expert and advanced solutions architect with many years of hands on experience both on offensive and defensive side. Knowledgeable at the highest level in application development, networking, data and databases, web applications, large scale Software as a Service solutions, cloud security and blockchain technologies.

I’ve been working with CISO’s of international enterprises, helping them set Information Security strategy, and overseeing the implementation of these recommendations. As part of these projects, I’ve been assisting companies to achieve compliance in GDPR, PCI, HIPAA and SOX.

Among my credits, I was a founder of a database security company GreenSQL/Hexatier which was acquired by Huawei and I’ve co-founded Kesem.io, Secure multi-signature Crypto wallet.

Specialties: Software and cloud architecture, Compliance (GDPR, HIPAA, PCI, SOX), blockchain technologies, software development, secure architectures, project management and low level research.