To my pleasant surprise I found there to be quite a lot of tools out there that do the job! As we develop in Java and I didn’t want to spend too long at work looking for a solution I decide to use a library called YUI Compressor; being all written in Java all I had to do was write some code to apply to some of our generated files. I then later found out that this specific library isn’t being developed for any more which is a bit of a bummer (it seems to do a good job!).
After seeing the results I was left a little intrigued in how such a library works so decided to begin writing one myself!
So far it only works on CSS (files and text strings) but seems to shrink them quite well! I had already implemented a method for replacing calls to rgb(r, g, b) with their corresponding hex colour and hope to flesh the library out some more. I have yet to look at the source code of YUI Compressor and am sure when I do I will learn a thing or two about what to do in my library.
I’ve called it LMinify, it’s more of a pet project than a professional tool like some the programs I found (feel free to use it if you like though). I am hoping to keep it’s dependencies low (currently the only external Library in use is Junit for the tests!) and am also hoping making it will teach me a thing or two and maybe come in handy at work!
It can be found here: https://github.com/LyndonArmitage/Lminify