Handling Static Conent in Web App


Performance and scalability: Handling Static Conent in Web App

  1. Handling Static Conent in Web App (3 messages)

    We have a application with heavy loads of Static Content to be loaded when a new Browser session is opened.The application is being deployed in a App Server(WAS 4.0).The problem now is whenever a new browser is being opened in the same client m/c the loads of static data(~100 files in form of js,xsl,dtd,css,gif) is getting reloaded for each browser opened creating overhead on the app server and there by reducing the Performance.

    My question how can we handle this static being reloaded every time One trick is as we are using WAS 4.0 which is A j2ee COMPLIANT SERVER all the content of Web App is packaged in a EAR file along with the static content.So taking out the static content from the app and placng in a different web server(like IBM Http server) may not be treated as a Option.

    My idea is:

    Can we have any option to configure the client machine( browser) in order to take the static conent( js, .gif, dtd)
    from temporary interent files folder?( in case if one session is already present) So that again separate request will not be sent by the browser for the same resourses which were already cached in the cleint machine during last transaction.

    Threaded Messages (3)

  2. HTTP Headers[ Go to top ]

    It seems that WAS is not able to manage correctly htpp headers- see http protocol specification- you can simply set these prameters by using
    response.setHeader("Expires", "Tue, 25 Dec 1993 23:59:59 GMT");
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-control", "no-cache");
        response.setHeader("Last-Modified", "FRI, JUN 25 2999 23:59:59 GMT"); response.set. Yoy can
  3. HTTP Headers[ Go to top ]

    Sorry previous reply was uncomplete:

    It seems that WAS is not able to manage correctly htpp headers- see http protocol specification- you can simply set these heders and the client application (browser) will understand if requested resource was modified from last request
        response.setHeader("Expires", "Tue, 25 Dec 2003 23:59:59 GMT");
        response.setHeader("Last-Modified", "Date in GMT format take this param from file modification date");

    you can write your own servlet that will serve static content if WAS is unable to handle this correcly. The most importatnt thing is to watch if-modified-since http header that is sent by browser. You shold not return data in case that resource was not modified from last visit. You should only set response status to response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); keep in mind that you should not send any data to the client in this time.

    See the snippet of code below

    phResponse.setContentType("correct connetnt type- for eaxample text/html");

    long lHeaderTime = request.getDateHeader("If-Modified-Since");
    long lLastModifiedTime = (java.sql.Timestamp) //get your file modification timestamp
    if(lLastModifiedTime > 0 && lHeaderTime >= lLastModifiedTime) {
            //do not write data to the output
    else {
    //write the data to the oputput stream
     ServletOutputStream out = phResponse.getOutputStream();
  4. Reverse proxy[ Go to top ]

    Use a reverse proxy.

    Configure IBM's HTTP server or Apache (they are the same, anyway) as a reverse proxy and cache the static files in the web server. Oversimplified, it requires something along the lines of:

     ProxyPass /app-dir http://was5host/x
     ProxyPassReverse /app-dir http://was5host/x
     CacheRoot /proxy-cache-dir
     CacheSize < NoCache *.jsp
     NoCache */servlet/*

    in httpd.conf.

    Hope this helps.