I am currently in the process of writing a javascript class that loads libraries from my server dependant upon what the site needs. Much like the Google API e.g. google.load('jquery','1.7.1').
One of the things that I would like to do is combine all the JS/CSS files into one and minify them using PHP. I have had a good look around the net and whilst I was able to find a fair few questions on Stackoverflow that refer to this topic, they seemed somewhat outdated. So, resultantly, I have decided to re-open this debate in order to gain some up to date info on this subject.
I was able to find two PHP Javascript minifiers on the net, these being
I did actually find a third (JSMin), but this was unmaintained
My questions are quite simple:
- Are these scripts reliable and maintained? Do they even need to be maintained?
- Do they compress CSS?
- Which script is better?
I haven’t use JShrink or Javascript Packer. I think the best solution is using Google’s Closure Compiler for JS minification. You can use their command line Java application on your server (if you have the rights to do so) or access their RESTful API through cURL or Zend_Request.
Don’t forget to cache the minified files and to reuse them if the source files didn’t changed.
Using cURL it would look like something like that: