Take the 2-minute tour ×

I need a tool which can minify, optimize and munge many files of those possible types

  • HTML (minify only)
  • JavaScript (minify, optimize and munge)
  • CSS (minify)

The final result should be one HTML file only with all JavaScript and CSS embedded or in the worst scenario 3 files respectively for HTML, JS, and CSS.

I am aware of tools like YUI Compressor etc. What I currently have not found is the type of compressor which will work on all those file types and merge them in one huge file only.

share|improve this question
Currently experimenting with Digua (digua.sourceforge.net) –  Gad D Lord Jun 28 '10 at 20:47
Question: how the hell can u merge all that into ONE file? ... unless all of those are already in one file, to start of with? –  Pure.Krome Jul 4 '10 at 11:42
They can be merged easily with a batch/bash script by appending one after another. –  Gad D Lord Jul 10 '10 at 15:49
It is not optimal to have JS+CSS embedded in HTML. It costs more network bandwidth when you have multiple HTML pages sharing the same JS+CSS. –  BalusC Jul 16 '10 at 23:39

7 Answers 7

up vote 1 down vote accepted

Gad, consider the drawbacks to minifying CSS. If you don't have a system where you edit normal/minify/ then deploy it can make later editing of CSS rather dicey.

I went through this whole argument on a big UI refresh project for an international bank. One site in particular was doing 1million+ visitors/day and bandwidth numbers were insane despite all our efforts to keep it minimal (every little bit adds up on a site that heavily trafficked) Upon business analysis by a large team of very talented minds, it was determined that we would take several steps, but NOT css minifying due to the added time it would take engineers to undo the minifying before fixing, minifying and redeploying for simple CSS tweaks. The numbers showed that even with a 5gb/day bandwidth improvement, it was still cheaper to not pay a UI engineer for the extra time.

We don't know your site's specifics, but there aren't terribly many that have to worry about the traffic my example uses. Run your site in Firebug's new speed analyzer and see what the real benefit could be from minifying.....now multiply that by your traffic. Usually, that number isn't too scary. Spend your time doing image sprites, combining css and js into respective files (better than mashing into individual php files due to caching benefits) to limit http requests, and ensuring that caching is properly setup. Run gzip compression. If after those steps you're not good, then take the site to a new level.

Keep it simple....it makes a huge difference in the update and maintenance portions of the site's lifecycle. With the time and headache saved, you can help us out with our questions :)

share|improve this answer
who would anyone undo minifying? That's useless of course. A large team of very talented minds could figure out that you should only have a development version and a simple automated process for deploying. Again undo minifying? Never heard of it. Consider javascript minifying where you simply cannot undo. You need a different approach that's for sure... –  galambalazs Jul 21 '10 at 9:32
In some business settings such as the one above, there's not an option to keep a separate piece of code in the codebase. If we minified and deployed that code, it became the code that moved forward to trunk. And, getting a separate business process to minify during the deployment process also would have been quite the challenge. Again, it gets down to how complicated your environment is and how many people you want to involve for a minor improvement in performance. Before I worked there, I wouldn't have understood how changing one character could take 5 people 3 weeks. –  bpeterson76 Jul 21 '10 at 12:24
"it was still cheaper to not pay a UI engineer for the extra time" An Engineer for css = overkill imo –  Enriquev Jul 23 '10 at 12:20
DailyWTF level system architectures notwithstanding, you should never minify code in place. I'm voting down the answer because we should provide technically correct answers here, not worse-case scenario driven pragmatism. –  Sasha Sklar Feb 9 '11 at 0:31
really? one person can't have responsibility to "recompile" the whole site whenever code is updated? can you explain why that can't be done at a large org? my old shop did. –  user1382306 Jun 4 '13 at 1:04

If you're not using gzip yet, start using it already and we can close this thing out ;)

share|improve this answer

My suggestion would be to put all of the JavaScrpt inside a <script> in the header, and put all of the CSS in a <style> tag as well. Then optimize to the best of your ability and then minimize it on your own. No software will ever be able to handle every case. If you are trying to minimize the file size then just remove the newlines and non-necessary spaces.

I also found this, which should work on your file with all 3 in it.

Also be aware that if you start removing optional tags you could run into some problems. Some browsers don't cooperate as well as they are supposed to.

share|improve this answer
Saying that no software will ever be able to handle every case is a pretty bold statement. What extraordinary cases would make this such a difficult task? The most imminent problem I can forsee is javascript using css selectors that need to someone be marked as constants so they don't get affected by the minification. –  Jamie Wong Jul 22 '10 at 23:11

As far as I know there isn't such a tool. If you use PHP on the server side, however, you can try PHP Speedy (not actively developed, but works) or Minify for automated minification, caching and gzipping (HTML, CSS, JS).

edit: kangax's HTML minifier (as Badger suggested) only does HTML minification.

share|improve this answer
I can not use PHP since there is no server-side :). The project is a bit odd and does not have a server-side like Java or Php. I found Digua (digua.sourceforge.net) - a tool which quite resembles what I need. Currently I am experimenting with it. –  Gad D Lord Jun 28 '10 at 20:49

you can use jsCompressor to compress and minify multiple JavaScript files and CSS Compressor to compress/minify multiple Css files into one file. and to optimize your HTML files you may send post request of your code to Google Clouser server which sends response with optimized Html code.

share|improve this answer

I suggest you look at the build script that's included in the html5 Boilerplate: http://html5boilerplate.com/. With some minimal tweaking it'll do what you're looking to do.

share|improve this answer

http://prettydiff.com/?m=minify will do exactly what you need, except that it only minify JavaScript and not obfuscate it.

share|improve this answer

Your Answer


