Friday, August 11, 2006

Keep Domino Web session alive with PeriodicalExecuter

I created a web application which required to keep the session with the Domino server active. The current server settings is only 30 minutes. Changing that is not an option because it will effect other applications. A solution is to always do a server request before the session time ends. A very easy way to do it is to use prototype.js PeriodicalExecuter. You can specify the number of seconds when should a function be triggered

new PeriodicalExecuter(KeepSessionAlive, 1200);

function KeepSessionAlive ( ) {
var ajax = new Ajax.Request("/icons/blank.gif",{
method:"get"
});
}


Every 20 minutes (1200 seconds) I call the function KeepSessionAlive. The function will make a simple request to the blank.gif icon on the server. This will keep the session with the server alive. You can use this function to refresh and update a view every few minutes. This is another one of the simple useful function provided by prototype.js.

4 comments:

Tommy Valand said...

A little late to comment, but you gave me the link.. :)

How do you ensure that the browser doesn't use a cached version of the image?

I'm a little paranoid on the caching issue, so I always put a random number at the end of the URL:

function rand(){return Math.round(Math.random()*5000)}

...
var url="someurl?open&"+rand();
...

William Beh said...

@Tommy. Good suggestion. Although so far my production implementation doesn't face that issue. Putting in the random number will make sure it will always send a request to the server.

Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

Unknown said...

This information is great for my present research project. Nevertheless, I'm gonna to send it to any online proof reading services to find and correct typographical errors and mistakes in grammar, style, as well as spelling!