Search code examples
phpcompressionminifyjscompress

Looking for a CSS and for a js file merger and minimizer


I'm working on a public project and one of the things we are after is a CSS file merger and minimizer and a js file merger and minimizer. The requisites are as follows:

  • No beta code. Only stable code.
  • Must be written in php.
  • Must work in php 5.4.
  • Must be compatible with php 5.3
  • The CSS minimizer program may be completely different from the js minimizer (it does not have to be a 2 in 1)
  • The minimized result must work somewhat so that it can be dumped to a file. Browsers only access the dumped file. This must be able to work with loads of work so minify, great tool but not an option.

If the system is only a minimizer I can do the merging in the server myself (string concatenation) and use the minimizer later.

When there's something new to compress, I use the system (e.g. a class, a function, etc...) that I call when I want to minify the js or the CSS. Its output is supposed to be placed to a file, so if it's output can go directly to a file great(!), if it's just a string returned to the program, good(!) My program is the one who knows when the compressed file is supposed to be substituted and the one who deals the access to the file.

This is for a project that must work where all outside communication by the php's initiative is disabled and where most functionalities are disabled to somewhat sound like. That means no url includes, no curl, no url file_get_contents(), no exec(), etc...

Note: There are lots of questions in this website about this subject. The problem is that most of them are to generalist and do not answer what I need (Ex: is more interested in suggesting YUI or compressors that are currently known to have bugs).

I already tried to find this in the internet but I can only find old abandoned projects or I get compressors that require the use of the command line interface.


Solution

  • For CSS, I personally use CSSMin with great results. It is a plain PHP solution, and it is even able to simulate CSS variables, with a @variable declaration.

    For JS files, I call Google Closure Compiler with curl which does not meet your needs.