5

I know of ways to minify JS and CSS files but is there a way to auto-minify these files in the production system? For instance, I modify something inside the original JS files and update the production environment. However, while using the JS files, it should use an auto-minified version of the JS file (preferably update the current minified version if the source files changed).

Considering that I work in both Unix and Windows environment, writing a bash script did not seem like a plausible idea. So anything that is OS independent or maybe something that uses PHP initially to do this would be great. Any suggestions?

Legend
  • 113,822
  • 119
  • 272
  • 400
  • See this related questions: - http://stackoverflow.com/questions/853295/javascript-build-tools - http://stackoverflow.com/questions/222581/python-script-for-minifying-css –  Oct 27 '10 at 04:57

2 Answers2

6

You might find value in minify. It uses PHP5, and can sit well on your production server.

From the website:

It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers.

Chetan
  • 46,743
  • 31
  • 106
  • 145
3

I agree with @RC, read those existing Q/As.

Also other options for your specific question:

  • Post-Commit hook - minify step
  • Build step during development, commit minified files
  • Server side filter that minifies on file change (Rails and other frameworks have this built in)
  • Enhance you deployment script to do the minify during deployment

Write these hooks in a cross platform language instead of bash. (JavaScript, Python, Ruby, etc).

Ozten
  • 188
  • 9