|
« Debian and Beta3 Update |
Zimbra Blog
| Zimbra Collaboration Suite 3.0 Released »
Roland pointed me to an article about the amount of Javascript on digg.com's home page. Seems a few Digger's found it interesting. Well here at Zimbra we've got tons of Javascript and CSS in our AJAX web app. I decided to try an experiment to see if the techniques we use for Zimbra, a rather large AJAX app would help a site like digg.
First some background on Zimbra's AJAX app and the techniques we currently use. Raw and uncompressed the Javascript alone is over 2Megs. To make our app easier to download we've made some optimizations.
For Javascript we combine all the files in to a single _all.js file. The order that you concat these files is important since the browser will parse the files top to bottom. The same reason why the order of the script tags in your HTML document would matter to prevent dependency problems.
We then use jsmin to remove comments, white space, and excess new lines. This gives on average 25-30% reduction in size. The final and most important step is to gzip the file. This gives on average 300-400% reduction in size. Some web applications will apply gzip compression on-the-fly, which for dynamic data is the only way. Here since the Javascript is static, which is true for most AJAX applications these days, we can pre-compress which will reduce latency and CPU overhead.
For CSS we also combine all our CSS files into a single _all.css file. This combined file is then compressed with gzip.
Now back to the experiment. I took a copy of Digg's home page and applied the techniques above. Combined, jsminified, and gziped the Javascript, then combined and gziped the CSS. Visually and functionality nothing has changed. Under the covers however the source is quite a bit smaller. I used Web Page Analyzer to compare the results. We see a 50% reduction in the number of HTTP requests and a 65% reduction in the size of the download.
Original:
Total HTTP Requests: 26
Total Size: 199246 bytes
Zimbrafied Digg:
Total HTTP Requests: 13
Total Size: 70040 bytes
Not bad at all... Took me longer to write this up than to make the changes and I think all digg user's would benefit from such a change. Not to mention digg itself would see a > %50 reduction in bandwidth usage which for a site like digg could be very significant.
Love working on ajax optimization problems like this? Check out our careers page and drop us an email.
Digg This
Posted by Kevin at January 28, 2006 12:13 PM
Trackback Pings
TrackBack URL for this entry:
http://www.zimbra.com/blog/mt-tb.cgi/52.
Posted by: ch0de at January 28, 2006 03:39 PM
Great article - can you explain how you pre-compress a gzipped file? I have only seen how to do it with an apache mod or through PHP, etc.
Posted by: JC at January 28, 2006 03:56 PM
That's amazingly cool. It's great people still do things just to be helpful, not for money and the like.
Good job.
Posted by: EJ Fox at January 28, 2006 11:11 PM
For this example I used the gzip ANT task in our build system. You could also use the gzip command found on most Unix type OS's.
Posted by: KevinH at January 29, 2006 12:20 AM
JC: Use mod_deflate.
God Bless ya!
Posted by: Simon_a_Christian at January 29, 2006 12:31 AM
Posted by: Ivan Minic at January 29, 2006 12:36 AM
Posted by: theCreator at January 29, 2006 01:51 AM
is it possible to send gzipped version only if the browser supports it? (Preferrably a prebuilt gzipped version)
Posted by: zanzina at January 29, 2006 02:20 AM
I also thought about gzip'ing CSS and Javascript files, but how do you handle these problems:
Internet Explorer May Lose the First 2,048 Bytes of Data That Are Sent Back from a Web Server That Uses HTTP Compression
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q313712
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312496
This looks like a serious road block.
Also, Mozilla and IE will only decompress files, if they have allowed compression (configurable by the user in Mozilla at least). So you cannot just unconditionally deliver gzip'ed content.
Also, I have read about older (not specified which) IE versions that will fire window.onload after script tags in have loaded their source, but before the source was decompressed and parsed.
Looks like Zimbra takes the "oh well, works for >99% of the users", it seams. Not that this is not unreasonable.
Also, there is a note on the Zimbra login page about caching problems with IE. Does the problem occur only with compression, or also without?
Posted by: Martin at January 29, 2006 02:40 AM
Zimbra is a great app, we use it, Digg is a great social news site. Glad to see two of my favourite things combined into something better! ;-)
Posted by: moebis at January 29, 2006 07:57 AM
@zanzina,@Martin
Yes we package and ship both a gzip precompressed file and a jsminified file (non-gzip). At run time we look at the browser headers(Accept) and to determine if they support gzip. So we handle the case where a browser doesn't support gzip or has it disabled. From our testing this seems to cover the problem certain IE(6.0 SP1) browsers have.
The IE cache problem is different. This is where the IE browser cache gets damaged/corrupted and will cause every image, script, etc to be read from the server each time. The fix here is to simply clear your cache.
Posted by: KevinH at January 29, 2006 09:44 AM
Duh... Tree, Forest and stuff. Of cause one can generate different and tags dependent on the client... Thanks for the slap :-)
But how about the problem described in the two knowledge base articles? It cannot be detected, so there is nothing one can do about it.What does Zimbra do about this?
I guess it depends on your assessment of the risk if you do not deliver compressed files to IE at all (or rely no user agent sniffing to deliver compressed files to IE6 SP1 and up only) or if you risk the breakage.
Posted by: Martin at January 29, 2006 11:25 AM
From our testing it doesn't always cause a problem. In fact we spent the better part of last week working with IE 6.0 SP1 around this issue and an unrelated problem with image caching. The hotfix[1] for this bug has been out since 2003, and there are so many other ways to get the fix (XP SP2, IE SP2, etc) that we still send gzip content to IE if it claims to support it. We also have a URL flag ?gzip=false where user's can disable gzip if they are unable to apply the hotfix, or get the fix via one of the many service packs.
[1] http://www.microsoft.com/downloads/details.aspx?familyid=A4EA08F9-BCCA-4CFF-AE0B-3F0FD945F586&displaylang=en
Posted by: KevinH at January 29, 2006 12:00 PM
Very interesting. I am trying this out myself and while I have compressed our css file using gzip, any attempt to load it does not seem to work.
Do we need to edit mime types on the server etc to enable this ?
Many Thanks
Posted by: Ian Mansfield at January 30, 2006 04:52 AM
Yes, you'll need to set the correct content-type headers. We use a ServletFilter but this could also be done with mime extension mapping.
Posted by: KevinH at January 30, 2006 07:44 AM
How can you have a 300% reduction in size? If you have a 100% reduction, is the size not gone? Are we talking some kind of negative dimensional incursion where the size moves to an alternate dimension, and then increases 300%?
Posted by: anonymous at January 30, 2006 09:00 AM
I would be very interested in seeing some sample code on how exactly you determine whether or not to send the GZIPped content, this would be very much appreciated.
Posted by: bartb at January 31, 2006 12:13 AM
@anonymous - Think about it in reverse. It's just a way of saying 3-4 times smaller.
@bartb - This code is available in our CVS. For more code related questions please join our forums.
http://www.zimbra.com/forums
Posted by: KevinH at February 2, 2006 12:39 PM
Very nice article. Funny, I called with someone at Zimbra today as I'm looking at getting a new mailserver for work. This blog and the way the guy was speaking on the phone shows a very passionate company. something sadly lacking in the corporate world.
Posted by: gerard van schip at February 9, 2006 02:17 PM
Hi Kevin,
Nice blog. I've written something similar.
http://www.peterbe.com/plog/gzip-and-slimmer-optimization
Combining the .js files into one will be my next challange.
Posted by: Peter Bengtsson at January 30, 2007 05:02 AM
hi guys,
well this is all true and we are basically doing the same thing!
im also using
http://developer.mabwebdesign.com/cssoptimizer/compress.html for css
and
http://alex.dojotoolkit.org/shrinksafe/ for js.
also gzip in web server.
now, i would like to hear what do you guys do with "heavy" ajax call, do you have a recommended method fo "shrinking" the content that is sent to server ?
Posted by: benny at January 31, 2007 10:32 AM
Yeah, anonymous is right on the reduction stuff. You can't say something gives you a 20% reduction, meaning it's 80% of its original size and then say something else gives it more than 100% reduction. With your 300-400% reduction logic, a reduction less than 100% would have to mean the file actually got larger.
You can say the original is 300% to 400% larger than the compressed version, but greater than 100% reduction makes no sense.
Posted by: FlyingAvatar at February 21, 2007 03:17 PM
AJAX, by now always the best!!! thanks for post. ;)
Posted by: francesco at August 18, 2007 05:23 AM
thanks for post :) very useful
Posted by: Frank at November 11, 2007 01:52 PM
Thank you,
AJAX, by now always the best!
Posted by: resimler at December 30, 2007 11:31 PM
Very nice article. Funny, I called with someone at Zimbra today as I'm looking at getting a new mailserver for work
Posted by: Firmalar at December 30, 2007 11:35 PM
Post a comment
|