Thursday, March 26, 2009

Java on AppEngine (or serverside JavaScript for the masses) !!!

But let's wait first for confirmation of the rumor.

Update: Following the first comment on this post ("Java != JavaScript"), it might look like I am confusing things, so let me clarify for those who can't remote read my mind (hopefully most) and are not familiar with Rhino, which is a JavaScript implementation written in Java, and allows serverside scripts to be written in JavaScript. And maybe just coincidentally, a few days ago a new release of Rhino has been pushed out. And for those who don't know, Norris Boyd, the main developer of Rhino is a Google engineer. So for me at least it makes sense to assume, JavaScript is part of Google's Java App Engine plans. But let's not forget, this is all based on speculation, and the only difference between now and the very same rumors "leaked out" by a Google engineer a few months ago, is that Michael Arrington has a lot of readers.

Monday, March 23, 2009

Cross-browser offlining

I just tried to find out what needs to be done to make a web application (let's take bespin as example) work offline. Unfortunately a google search for cross browser offlining did not point to any magic solution. So let's start with what I knew already about this:
  • offlining the static resources is the easy part and modern browsers and google gears provide all kind of support for that.
  • offlining the dynamic requests is extremely difficult. The server logic needs to be modeled on clientside and the risk of getting data inconsistencies is big. So let's leave that part for another day.
Unfortunately all the popular browsers (I tested with the newest betas) and google gears provide different ways of how to handle the offlining of static resources:

Firefox 3.1beta

Supports the HTML 5 offline API and has a menu option to simulate the offline mode. The static resources need to be listed in a manifest file:



and that manifest file name becomes an attribute of the html tag of the app start page:
<html manifest="/tests/th/cache-manifest">

Safari 4beta

Also supports the HTML 5 offline API, therefore everything the same as with Firefox, except there is no easy way to simulate the offline mode. Just turning off the internet connection does not help if you use a server on localhost for development.

Google gears for all the other browsers

Now it's getting a bit more complicated. First you need to find out whether gears is installed, and if yes, load the cache manifest file, which unfortunately has a different format (JSON) than the HTML 5 version:
// cache-manifest.gears
"betaManifestVersion": 1,
"version": "site_version_string",
"entries": [
{ "url": "/index.html" },
{ "url": "/default.css" },
{ "url": "/images/logo.png" }
And the loading of the manifest has to be done in Javascript:
if (google && google.gears) {
var localServer = google.gears.factory.create('beta.localserver');
var store = localServer.createManagedStore('test-dev');
store.manifestUrl = '/cache-manifest.gears';
Because the HTML 5 / gears manifest files have a different format and easily grow beyond manually manageable size, a tool (or a custom build step) is necessary to create and update the cache manifest file for complex apps.