Howdy folks! Just was browsing [url]www.aceshardware.com/[url] and they mentioned they were using a technique called "HTML Compression" to speed up page download time. Can anyone explain the technique, or at least tell me where I could find products or (preferrably) libraries or example code on how to do this? They mentioned a forum index page that used to take 30 seconds to load over 56k modem now takes only 5 seconds! I've certainly got a few large pages that could do with this speedup! Thanks!
CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)<br />Author of <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi" target="_blank" rel="nofollow">Posts in the Saloon</a>
Joined: Sep 29, 2001
HTTP Compression is a method of sending information to the browser which has been compressed with the gzip deflate algorithm. You achieve this by chaining the response OutputStream with a GZIPOutputStream in your Servlets e.g OutputStream out = response.getOutputStream(); writer = new PrintWriter(new GZIPOutputStream(out),false); //set the header response.setHeader("Content-Encoding","gzip"); //your normal servlet output goes here...e.g. writer.println("Compressed Hello World!"); writer.close() This only works with browsers that can accept the compressed information. To find out if the browser does you check Accept-Encoding to see if there is an entry for gzip by inspecting request.getHeader("Accept-Encoding"); You'll be UNHAPPY to know that not all browsers support this feature!!! Especially if you want to use this for the same company as your other post. Early versions of Netscape on Win platform and IE on non-Win platforms generally don't support this apparently, but it doesn't matter, you just use an if statement in the Servlet and depending on whether they have an appropriate "Accept-Encoding", you use the GZipped Stream or not. Make Sense? Using HTTP Compression only really helps with larger page sizes - you have to remember there is a price to pay in getting smaller page sizes - the time it takes to perform the compression at the server and the time it takes to decompress in the browser. Okey doke, confused? Well, lets make things really simple. You can buy the book "Core Servlets and JavaServer Pages" by Marty Hall (ISBN can't-be-bothered-to-look) and look at Chapter 4. Or if you are really cheap and lazy you can download an example from the website http://www.coreservlets.com (HINT:You're looking for Chapter 4 EncodedPage.java) OKAY! OKAY! Here's a bloody direct link to the source code of the servlet in question:http://archive.coreservlets.com/coreservlets/EncodedPage.java Some people are so lazy! No rest for the wicked. Andre.
Joined: Aug 02, 2001
Thanks for all the info! That's just what I was looking for! I'll have to give it a try and clock some load times. Any idea if Mozilla or the Linux browsers(such as KDE browser) do gzip?