I had suggested an approach to this which automatically generates the minified file from a hash sum of the last modified time of all included files. That way, if any one of the files has a different "last modified" time, the minifier would know it needs to be recompiled, otherwise, it would just load the min file that's already there. The entire discussion is here: https://github.com/phalcon/cphalcon/issues/549
Essentially, this is how it would work:
$assets->addCss('file.css');
$assets->addCss('file2'.css);
Compiled file would be output file name + md5(filemtime('file.css').filemtime('file2.css'));
, so something like 'minified_3q4un9028tb26782638794c238462.css'.
On next request, the file name is recalculated. If the filemtime is the same, the hash stays the same, and we can do a check like
if (is_readable($outputFile)) { // echo this minified CSS file }
however, if the filemtime is different, the hash is different, and the file automatically doesn't exist. This signals the minifier that a recompile is in order and it regenerates everything.
This ensures the minification is rerun only after every file change (in other words only when needed) and also makes sure your clients get the most up to date CSS and JS at all times, because the filename (the hash part) changes on every change and isn't stuck in cache - basically, this is like versioning. This is how I've had my own minifier for years and it's never let me down.
I've created a new issue for it here: https://github.com/phalcon/cphalcon/issues/925