Dojo Gotcha – Initialization with window.onload

I’ve been playing with Dojo, specifically the rich text editor, and came across a Gotcha in setting up the whole thing, which isn’t documented too clearly. Specifically, Dojo needs its own window.onload – if you have your own window.onload (as you probably do if you need any initialisation), it will conflict with Dojo!!!

The solution is described here (though it seems Dojo changed a property name a few months ago, from baseRelativePath to baseScriptURI). This is working for me – in my HTML:

  1. <head>
  2.     <title>My App</title>
  3.     <script type='text/javascript'>
  4.             var djConfig = {
  5.             baseScriptURI: "/ddq/js/dojo/",
  6.           isDebug: true
  7.         };
  8.     </script>
  9.      <script type="text/javascript" src="/javascripts/dojo.js"></script>
  10.      <script type="text/javascript" src="/javascripts/myapp.js"></script>
  11. </head>

In myapp.js:

  1. dojo.require("dojo.event.*");
  2. dojo.event.connect(window, "onload", myappInit);
  3.  
  4. function myappInit() {
  5.     alert("Okay, here we are in the old window.onload and it's still running :-)");
  6. }

It might be a good idea for the Dojo crew included some explanation of this in the standard heres-how-to-setup-dojo.js-intro docs. Maybe someone with in-depth knowledge of Dojo could infer that window.onload must be used by Dojo, but the average programmer taking Dojo a spin won’t.

Links:

Dojo. Awesome framework. Bring on the doco.

Wanted: Massive Local Storage

Local storage – beyond 2KB cookies – is now a step closer with the latest Firefox effort. You get a local storage API like this:

javascript

  1. sessionStorage.setItem(..)
  2. globalStorage.namedItem(domain).setItem(..)

The fantastic thing is Brad Neuberg’s Dojo work means we can code independently of the local storage mechanism. Since IE also has local storage, as well as Flash, most bases are covered, or soon will be: Anyone with EITHER IE or Firefox or Flash will have local storage. (Incidentally, we had a discussion in the comments on Ajaxian about the possibility of S3 and other remote bindings as well, which I’m guessing Brad will implement at some point.)

But what I’d like to know, what I’d really really like to know, are the limits for these various techniques (I think Flash is 10MB per domain, right?)

As I’ve said before, there are valuable applications of massive storage – hundreds of gigs, e.g. media players that store data server-side, but cache content locally to cut down on the need for streaming from the server. Hopefully, these storage technologies won’t try to second-guess the imagination of web developers by setting a dumb arbitrary limit that “no-one would ever need more than”, like 100MB or 1GB or whatever.

If there’s room on my hard drive, and I trust the domain, let me store as much as I please.