CSS minification library for codeigniter
For my latest project, I wanted to be able to easily minify CSS stylesheets, using the simplest syntax possible, ideally using a simple tag in the header, like
After some searching, I found a css minification library for PHP, minify
It was very easy to modify it so that It could be used in our CodeIgniter applications like any other libraries. All I did was wrap the main minification function in Codeigniter specific code. I modelled the interaction on the image library, as I guess that’s what most people are used to.
How to use
Using the library involves loading it, setting up an array with some configuration values, such as the source css file(s), the destination file (optional) or the time that the generated file should be cached, and finally initializing the library with the configuration array() .
The following code, which should go in your controller, will look very familiar to Codeigniter users.
Will output the following stylesheet tag:
Get It!
You can get it from GitHub. Don’t forget to fork it if you think you can make it better!
Finally
I’m not sure the way I’ve done it, using a
array and so on, is the best way. It might be a bit overkill for such a simple library. I’d love to hear your thoughts on the subject.