Does anyone know of a good way to automatically run certain file types through a processing script on upload? I'm trying to accomplish automatically minifying CSS and Javascript when I upload them to the server, keeping a nice, human-readable version on the local side while keeping a minified one on the server. I'm currently using WinSCP on Windows, which is scriptable to some degree but might not be scriptable enough. I'd probably need some kind of cobbled-together solution, so don't be afraid to suggest something with duct tape in it; however, I do need to do the minification on my local computer and upload the squished file, since I use shared hosting and can't install junk on the server.
Thanks.
Well, to minify CSS is just a couple of regexes.
And Dean Edwards's Javascript packer has been ported to PHP, Perl, .NET and WSH, so if you're using any of those technologies, you could actually have it running on your own server. ...Just remember to cache the results!
I recommend creating a makefile to solve this particular problem, here's a quick and dirty makefile I'm using for a site of mine:
Then all you have to type is:
First it takes all of your development files and concatenates them into a single file, then the concatenated file gets compressed and copied into your public directory. I'm using YUICompressor for compression, it works quite well.
I like Minify. It supports compressing and trimming html, javascript and css on the fly.
It is quite flexible, an can be integrated into existing apps.
Some of the more advanced features is combining multiple javascript files into one, same for css. It has multiple ways of defining which files to combine, which is usefull for testing purposes. This way you do not have to modify the settings every time.
I suggest compressing (by all means in some automated way) on your development machine and testing it there before uploading to your live server. Fundamentally changing your JavaScript as the last stage of your deployment process is an obvious risk for introducing errors.
Since you're on shared hosting, I'd just suggest using the YUICompressor, and running your css/js files through it prior to uploading them. Be sure not to lose your original files - it could be a pain making future changes.
You could also place a script on your server that would periodically re-write your css/js files, passing them througha minify-process, and manually invoke this script after doing an upload.
I just wrote this minfier script in python. Like Bills solution, it uses the YUI compressor, but will work in a make-less environment. It assumes that the raw (unminifie) files will be in /some/path/src/, and that the minified versions should go in /some/path/. It also assumes that the yuicompressor jar file is in the current folder: