Skip to content Skip to sidebar Skip to footer

Dojo And The Offline Application Cache

We've been working on an offline capable JavaScript applicaion using Dojo and the storage and offline capabilities available in newer browsers. The application is quite large, but

Solution 1:

When you use off-line, (most likely mobile), most of the time you'll need an optimized build as well. You don't really want to offline a few dozen files.

I don't think XHR works offline, so any resource you load via XHR (that includes scripts, i18n bundles and other dynamically-loaded resources that are triggered via href) you should store into localStorage, and then branch off to load from loaclStorage instead of XHR when offline.

Now, you really need to be making an optimized build if you are running on the iPhone, iPad or an Android device. Also consider using the Closure Compiler to further optimize your build. See link below.

http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t

Solution 2:

The issue is that dojo does a few initalization XHR Requests. It goes online to fetch its localization bundle and any .smd files for the RPC feature.

XHR cannot access the offline applicationCache, even though the bundle and smd files are avaliable there they wont be found when Dojo asks for them.

An alternative is to leave them outside the manifest file, but that means dojo wont start offline anyway.

We fixed the issue with the .smd file by adding the service specification object located in the .smd file directly to the constructor of dojo.rpc.Service. This meant that dojo had all it needed and no longer had to fetch it.

The localization bundles was different. In the end I made sure that they were appended to the end of dojo.js, letting the dojo.provide statements take care of the rest. In essence I modified the build script (a bat file for us) to after building put the compacted localization bundle at the end of dojo.js.

Now dojo can start offline.

Solution 3:

Are you using a manifest file for an HTML5 application cache? If so, you need to explicitly list files and directories to cache. Like all other resources, your built localization bundles must be accounted for in your manifest, either in the CACHE section or in the NETWORK section

Post a Comment for "Dojo And The Offline Application Cache"