Earlier, I suggested to use Code Downloading in order to reduce the size of AJAX application. I left the term undescribed, but I will change this now:
As JavaScript is an interpreted language, it is quite easy to load additional code, even after the application has “started”. This means that only code absolutely necessary to display the app has to be loaded initially.
In the following example, we define a function test() in the context of an object App. Then via Ajax the original code is overwritten. Naturally also new functions can be loaded.
The downloaded code is eval’uated, i.e. it is executed. You cannot only execute statements but also define variables and functions.
Source of load.js:
App.test = function() {
alert("additional code loaded");
}
I have set up an example implementation of this.
This allows more flexibility for larger apps. My “negative” example, Kiko, could use this method to enormously reduce the amount of code to be loaded initially.
I alse see the possibility to only store encrypted Javascript source code on the server and decrypt it on-the-fly (of course also this would only prevent script kiddies from stealing, but it could challenge some hacker a bit more).