There are many tools, frameworks and packages that deal with the problems you described. In general, they belong to the category of assembly automation , so you can start with this.
Minimization can be easily performed during the build process by the build server.
Deployment, however, is a huge topic in itself, and there are various tools to help you with Capistrano , apparently the most popular.
Anton Gogolev
source share