PHP - JS and CSS minifier

I have a simple CSS minifier that ... all it does is remove spaces and comments. I am pleased with this, but if there is anything better, let me know.

Now for JS minifiers I have this beast: https://github.com/rgrove/jsmin-php/blob/master/jsmin.php , of course, I have a rather long JS script. I want something long to thin out pretty quickly. Minimizing jQuery (I know it already got minified) takes 2 seconds, sometimes even 4 or more! I will not have files the size of jQuery, but I can get about half, and I doubt that 1-2 seconds to load one JS file is very attractive.

I am wondering if there are any quick minifiers there? I only need a minifier, I do not need something that unites, caches, etc.

+4
source share
3 answers

You don't need a quick minifier - just create (reduce) a new version of your javascript when making changes and save it all to a js file

+3
source
<?php $js = file_get_contents($_GET['f']); $md = md5($js); // you can use sth faster, such as date comparsion if (file_exists('cache/'.$md.'.js')) { echo file_get_contents('cache/'.$md.'.js'); } else { $min = yourJsMinifierFunc($js); file_put_contents('cache/'.$md.'.js', $min); echo $min; } 

Ok, this will work for you. After you modify your .js file, it will be reduced and cached.

+2
source

I suggest you take a look at the Assetic library . With Assetic, you can manage all your assets from PHP, applying filters as needed.

0
source

All Articles