Software Development in Brisbane

Archive for May, 2003

Caching Dynamic Content

Saturday, May 3rd, 2003

A common use case in building a data-capture application is to select something from a decent sized list.

You don’t want to have to send the whole list down to the client, but do want to update it when the data actually does change.

One answer is to split the data out into a seperate file, and then write it in using DHTML and JScript

Here is what I came up with (tested under IE only :-) )…

I started with looking around for information on Caching. I found this Tutorial, and a bunch of stuff on preventing caching (JGuru, and JDC, and more), suprisingly I ended up at Microsoft which had some of the most practical Performance Tips for the web that I could find.

I ended up putting the following snippet in the jsp that contains the data:

    response.setDateHeader("Last-Modified", lastRefDataUpdateTime);
     //check the data every 15 minutes after loading, force
     //a reload if a day has passed between loads
     //(session timeout makes this a bit redundant).
    response.setHeader("Cache-Control", "post-check=900,pre-check=86400");

Another cool feature mentioned in the MSDN article is the use of the DEFER attribute on Script tags. A bit of a google found this.

So now on the login page I pull down the data asynchronously when the user first logs in using:

<script src="datafile.js.jsp" DEFER></script>

Ending up with a quick little widget.

Dynamic Tree Widget

Friday, May 2nd, 2003

I just went through the process of setting up a dynamic tree widget, and thought I should type up my experience with this. If for no other reason than keeping the information alive for myself in the future.

The tree is based off of the Tigra Tree widget. Their tree is a Java Script/DHTML one. It has a nice MVCish structure with the Model for the tree seperated quite cleanly from the view.

I made the following changes to the base product:

adding an ID,
passing in the path to the current selection (useful for returning to a page and viewing which one was selected — I pass in the path rather than deriving it to make it perform when there is 4000+ nodes in the tree).
open the tree to the current selection.
improvment of the lazy loading features.

Producing a nice performant tree — I would love for someone to pay me to write an open source tree some time (hint hint).

I just needed to cache the data on the client so that it didn’t have to get reloaded…. but that deserves it’s own entry ;) .