We have a PhoneGap mobile project which uses Dojo. In a given HTML page, e.g. index.html, we would have a JavaScript tag similar to this:
<script>
require(["path/to/myApp", "dojo/domReady!"], function(MyApp) {
new MyApp().startup();
});
</script>
path/to/myApp.js would then be a class which performs the necessary functions, e.g.:
define(["dojo/_base/declare",
"dojox/mobile/deviceTheme",
"dojox/mobile/compat"],
function(declare) {
return declare(null, {
startup: function() {
// create and display views etc.
}
});
});
What we are trying to do is implement an auto-update facility along the following lines:
- At startup, use AJAX to check with the server if the client app version is current.
- If the client is out of date, send new JavaScript (and/or HTML, CSS) to the client as needed.
- The client stores the JavaScript in local storage on the device.
Given this scheme, at startup the client would read the JavaScript from local storage and execute that code, replacing path/to/myApp.js. What I am struggling with is tying this into Dojo's "require" AMD functionality. I think I would still need to use the Dojo loader in order to resolve dependencies etc.
From what I can see, the Dojo loader uses "require" to locate a DOM node to which it then adds a "script" tag, and finally it sets the "src" attribute of the script tag to "path/to/myApp.js" (in this example). I need a way to change this behavior to instead run the updated JavaScript which is now fetched from local storage on the device. This will enable us to auto-update our app from the server without requiring repeated re-deployments to the app store for small things like bug fixes.