Making Applications Work Offline

Several weeks ago, I posted some thoughts about AJAX in particular and web applications in general.  I talked about the fact that web applications trade user productivity for ease of deployment.  I bring this up because I want to talk about something that has always puzzled me. 

Periodically, customers ask me how to make web applications work offline.  They want to install a web server on a user's laptop so that, if they are disconnected, the users can point their browser at the local web server and keep working.  This seems to me to provide the worst of the web world (the less productive user interface) and the worst of the rich client world (all of the code on every server now has to be deployed to each of the laptops).  It seems to me, that if you are going to have to deploy code to the client anyway, why not deploy a rich client app and make it work online as well as offline?  That way, you can provide a better experience for your users.

The trick to writing an application that works offline as well as online (regardless of whether that application is web based or client based) is dealing with data.  You have to maintain a cache of the data on the laptop.  In addition, when the laptop is offline, you have to maintain the changes in a queue so that they can be passed to the server when connectivity is re-established.  The smart client application block provides guidance for dealing with these issues.  It talks about both a database driven approach (which uses replication) and a services based approach (which uses message queuing). 

SQL Server 2005, if you are able to use it, introduces a new feature, SQL Server Service Broker, which is a message queue inside the database.  This provides an option for combining the database driven and services based approaches.  SQL Server Express, a freely re-distributable version of SQL Server 2005, provides the ability to use service broker, as long as messages are sent to a licensed (non Express) version of SQL Server 2005.  Because of this, it is a great option for making applications work offline.

-David