Short Version
When using file compressors like YUI compressor, what is the proper procedure for deploying your website, so that you don't have to mess with compressed files during development time? Should there be a compression script as part of the release process?
Long Version
I just joined a project where we use YUI compressor for our JS and CSS files. I ran into some chunks of code that to me, seemed to smell very badly. I'm wondering if there is a better way to do this.
I think that while working on the code, developers should be free to work with the uncompressed files, and have the website still work and reflect their changes as they go. Then the altered css and js files can be compressed at release time. That's not quite how it goes here.
Basically, on of our core php pages does a check on PHP_SAPI, and if it's command line, runs the compressors. This consists of running an exec
on git log
and then some sed
magic to get the current revision number (to be used as a css and js file version), then proc_open
ing the yuicompressor, run that on the files, a few more exec
s to add the new files to git... and then some voodoo reaches into the php file itself (yes, it's self-modifying) and changes a $version
variable declaration to the new revision number. This variable is used to include
the correct css and js files.
When I first checked the code out of our repo, the website ran locally, but there was no css. I was told by a colleague that I needed to run a shell script that invoked the incantation above. This took about half an hour of tweaking file permissions before it succeeded.
Does this smell as bad as I think it does? How can we get rid of this as a development step and have it possible to just include the regular uncompressed files during development? As it is now I can't make changes to said files and see them immediately. The problem with doing it at release time is that the includes would have to change to the compressed files at the time the files are compressed. It seems like that would require scripts that modify the code as well. Any ideas?