views:

1070

answers:

11

I am doing speed optimization for my website application. And I found some practises to do that. For example Best Practices for Speeding Up Your Web Site from Yahoo. Among them are:

  • Minify JavaScript and CSS.
  • Minimize number of HTTP Requests by combining several files (css, js) into one.

My question is what infrastructure, tools and building process you use or can recommend to perform that?

+2  A: 

You can use YUI Compressor.

It can compress JavaScript as well as CSS. Just run it for all your files, then concatenate them into one 'package' file. You can either do that manually, write a Makefile or use some script to compress "just-in-time" on web request, although you might want to cache the resulting file.

Ferdinand Beyer
+4  A: 

According to the JavaScript Compression Rater, the most efficient tool is the YUI Compressor or JSMin.

Gumbo
nice site, but it says packer 3.1 for me?
annakata
That’s true. But packer takes up to 1200 times longer than the YUI Compressor or JSMin.
Gumbo
That's compress time though, which less relevant than the - also slow :) - decompress time. I guess this makes YUI the best across the board answer, I might switch based on this. +1 sir
annakata
I don’t know about the decompression time. But I don’t want to wait up to 10 minutes to compress a file after every change I made for just a 1 or 2 percent gain in file size.
Gumbo
A: 

Big fan of Dean Edwards /packer/ myself - comes in a variety of flavours.

annakata
Packer is cool. But it delays running due to the unpacking stage. People are moving away from it now.
Nosredna
Last time I benchmarked it wasn't significant, but based on Gumbo's posts I'll be looking at YUI again.
annakata
+1  A: 

The Yahoo tips are excellent. I use gomez to test the results of optimization efforts. Minification is a good step. I've found bigger impacts can usually be made by adjusting the way pages are put together (particularly in reducing how much images get cut up into little pieces to reduce the number of requests). Anyway, this yahoo blog gives a pretty good rundown of minification tools. I typically stay away from obfuscation unless there's a compelling reason beyond the relatively small performance kick. The actual steps to install and use a minification tool are relatively straightforward.

codemonkey
A: 

By following yahoo blog link I've found one real solution - "Make your pages load faster by combining and compressing javascript and css files" by Niels Leenheer.

Sasha Yanovets
A: 

Or you could just configure your HTTP server to GZIP compress all text documents.

Software Monkey
I'll never figure out why some people down-vote some answers... this is a perfectly legitimate answer to the OP's question.
Software Monkey
THe question was for a minifier and packer. Doing both of these as well as compressing will give the best performance.
Matt Lacey
+1  A: 

I do ASP.NET, so I use CruiseControl.NET with NAnt for my build process. A part of this build process is compressing with YUICompressor which in my experience is the best compressor out there.

If you don't do ASP.NET, theres still the original CruiseControl with Ant that you can use in the same capacity.

The reason I find this a superior set up is because a) all the tedious stuff is automated and b) if you're testing on your own machine you dont have to debug a single super long string of JS :)

Darko Z
+1  A: 

I've integrated minification to my deployment process. I do it in perl with packages JavaScript::Minifier and CSS::Minifier.

During my development, I want to keep the script expanded. I put some comments in my HTML so that my script knows which files to put togetheer and minify:

<!--- MinifyJS[js/minified-1.js] -->
<script src="..."></script>
<script src="..."></script>
<!-- end[js/minified-1.js] -->

<!--- MinifyCSS[css/minified-1.css] -->
<link ...>

A couple of regular expression, and I quickly get a "production" version with minified files.

Julien
A: 

For compressing everything before uploading it to web, this program is great both for CSS/JS/HTML:

http://www.w3compiler.com/

It's even possible to select areas not to compress, as it's not all MVC codes in your markup that supports getting compressed.

And it saves backup files each time it compress your files, so you can easily decompress it with just a click.

olemarius
A: 

I've found Minify most useful for my PHP projects. Very easy to use, just saves time configuring minimization, compression and caching of CSS and JS files manually. Also has a neat grouping feature.

Some notes about YUI Compressor

  1. YUI Compressor generates without line breaks at all while Minify has some.
  2. Be careful if you have escaped strings. I've found out that YUI Compressor unescapes them. So strings like "\'" become "'".
0xE1E0
+1  A: 

I wrote my own custom manager for this. It uses google's closure compiler and compresses files only when needed in release mode. Check it out:

http://www.picnet.com.au/blogs/Guido/post/2009/12/10/Javascript-runtime-compilation-using-AspNet-and-Googles-Closure-Compiler.aspx

Thanks

Guido Tapia

gatapia