Enterprise grade Java.
You'll read about Conferences, Java User Groups, Java, Integration, Reactive, Microservices and other technologies.

Tuesday, February 10, 2009

Using HTML and HTTP Compression with Weblogic Server

07:06 Tuesday, February 10, 2009 Posted by Markus Eisele
, , , , ,
Have you ever wondered about the extra spaces in your HTML output from JSP Pages or Servlets? Even the ones, dealing with webdesign on more or less older browsers did :)
Beside the formatting this could also have an impact to overall application performance, if you are delivering big pages.
The first thing, that came to my mind was the gzip compressed HTTP response. Apache 2.0 comes with the mod_deflate, which adds a filter to Gzip the content. Filters can be blanket — in Internet Explorer everything is compressed — or selective — compressing only specific MIME types (determined by examining the header generated, either automatically by Apache or a CGI or other dynamic component.
To enable blanket compression, set the SetOutputFilter directive to a Web site or Directory container, for example:

<Directory "/your/path/to/htmlroot">
SetOutputFilter Deflate

You can take advantage of this using WLS if you use the WLS Apache Plugin, too. Used in combination, you get a gzip'ed http stream, that reduces the amount of data transfered to the clients.

If you don't have an apache in front of your server, you can still have a servlet filter installed, which could do the gzip compression of the content for you.
There is a quick samle available from bea (download: http://ftpna2.bea.com/pub/downloads/Gzipfilter_war.zip). Simply add the weblogicx-gzip.jar included in this distribution into your war's WEB-INF/lib directory. Register the gzip
filter in your web.xml as shown below:


After this, you have to map all resources which can benefit from compression such as
.txt, .log, .html and .htm as a filter mapping.. You can also use the filter to compress output from jsps and other dynamic content. Typically compressing certain image types does not prove to be advantageous since they are already compressed
so make sure they are not mapped to the gzipfilter.


Of corse there are plenty other solutions out there. You could even write your own gzip filter. Find the right solution for you. This should not be a productive solution anyway. It consumes too much server ressources and is something the mod_deflate could do much more efficient. But it could be handy for tests and debugging.

To optimize the output of your HTML code, you can use the newly added feature from the Weblogic Server (>=10.x). It's called HTML Template Compression. To use it, you simply have to add the following code to your weblogic.xml:


This removes any extra whitespaces from the generated HTML output. For example:


will be rewitten as: