Blogs about Deep Learning, Machine Learning, AI, NLP, Security, Oracle Traffic Director,Oracle iPlanet WebServer

  • June 8, 2006

Dynamic compression of static files in Sun Java System Web Server 7.0

Dynamic compression of static files in Sun Java System Web Server 7.0

    Check out the new cool features in Sun Java
System Web Server 7.0 which can be downloaded for
free from http://www.sun.com/download/index.jsp?cat=Web%20%26%20Proxy%20Servers&tab=3&subcat=Web%20Servers .

In this blog I will talk about dynamic compression of static files.

    We have also implemented caching of compressed data
for static files. We have added a new service function "compress-file" which will
compress static files (if the compressed file doesn't exist) and serves
it from the cache if the compressed version already exists.

Lets say if I want to create .gz files on the fly for  static
files, all I have to do is to modify obj.conf as shown below. Use it
with find-compressed SAF.
Add it before send-file


NameTrans fn="assign-name" from="\*.html" name="find-compressed"

Service method=(GET|HEAD|POST)
type=\*~magnus-internal/\* fn=compress-file subdir=".compressed-files"

Service method=(GET|HEAD|POST) type=\*~magnus-internal/\* fn=send-file



<Object name="find-compressed">

PathCheck fn="find-compressed"

Note that subdir is a directory name only relative to the
directory in which the original
non-compressed file is located. "." means use the
same directory as the original file to create compressed files.

this new "compress-file" SAF takes are subdir,
check-age(true), vary(true), compression-level(6), min-size(256),

Let me take an example, if we have a static file in the docroot
ls -al

-rwxr--r-- 1 root root 1386 Aug 1
21:16 static1.txt

Send a GET request with Accept-Encoding: gzip header,
it returns the compressed content,
telnet 0 2701

Connected to 0.
Escape character is '\^]'.
GET /static1.txt HTTP/1.0

HTTP/1.1 200 OK

Date: Mon, 01 Aug 2005 15:47:11

Content-length: 892
Content-type: text/plain
Vary: accept-encoding
Content-encoding: x-gzip
Last-modified: Mon, 01 Aug 2005
15:47:11 GMT

Accept-ranges: bytes
Connection: close

iñÂ6ì¹­ ³Í§8z

We can verify that the Web Server creates a .gz file in .compressed-files subdirectory.
# ls -la
drwxr-xr-x 2 webservd webservd
512 Aug 1 21:17 .compressed-files

-rwxr-xr-x 1 root root 1386 Aug 1
21:16 static1.txt

# ls -l .compressed-files/
total 2
-rw------- 1 webservd webservd
892 Aug 1 21:17 static1.txt.gz

Also note that the content length on access file is the same as the .gz
file in the .compressed-files
tail ../logs/access

format=%Ses->client.ip% -
%Req->vars.auth-user% [%SYSDATE%] "%Req->reqpb.clf-request%"
%Req->srvhdrs.clf-status% %Req->srvhdrs.content-length%

abc.def.com - -
[01/Aug/2005:21:17:11 +0530] "GET /static1.txt HTTP/1.0" 200 892


Join the discussion

Comments ( 2 )
  • Joe McCabe Monday, February 26, 2007

    This may be obvious, but never-the-less:

    This requires that the document directories have write permission of UID that Web Server is running as. Lacking these permission will result in errors in the errors log indicating an inability to create the file structure.

    How aggressive is Web Server in checking for freshness of the compressed file vs the uncompressed original?

  • Meena Vyas Tuesday, March 6, 2007
    When the request comes to "compress-file" SAF or "find-compressed" SAF, if "check-age" is true, it compares the timestamp of the two files before serving it. You can set "check-age" to "false", for faster results in which case it will not compare the time stamps.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.