prototype.js just for AJAX

As I stated earlier, the prototype.js library is too large for just using AJAX. In its current version (1.4.0_pre10) it weighs 36KB and contains lots of other features that are most probably not needed when just dealing with AJAX.

I have therefore created a smaller version just for AJAX, based on 1.4.0_pre10: pt.ajax.js 8.9K

It now has only a quarter of size and still provides some nice features such as $ as a wrapper of document.getElementById.

Creating this was not too difficult: it is merely a combination of 4 files that make up prototype.js:

Just do copy and paste into a new files, i.e. copying each file to the bottom of your new javascript file.

As you can see, you can easily create your own customized (smaller!) version of prototype.js to fit your needs.

ajax, prototype.js, customized

Rise of slow AJAX applications

The current movement towards AJAX is a good thing. If it really were a movement towards AJAX. In my eyes it is rather a higher acceptance for Javascript applications. Of course, it is quite naturally in the early stages of a “hyped” technology to observe many misuses; they use AJAX just for the sake of using AJAX.

Pages get more voluminous because so much code has to be loaded to the browser (which makes the browser slow again) so you could just begin to use the application. This somehow reminds me of all the flash apps. Waiting for hours to load the page and you’ll stick to that page for half a minute. (I do have a broadband connection. Still a page with 30kb loads 10 times faster than a 300kb page).

A negative example for this is Kiko, a web calendar. It has a nice “Kiko loading” box which already hints that they are doing something wrong. All Javascript files are included via server side scripting instead of loading them via <script src=”xyz.js”> which would allow the browser to cache the file.

Kiko is just one example, there are others doing similar mistakes.

I think that the current usage of AJAX is a misuse of the browser. They are designed to render web pages (i.e. (X)HTML pages). Javascript is a bonus. Large data strucures can slow down browsers enourmously (they are still interpreting Javascript just in time).

As a conclusion I want to come up with some essential features for AJAX applications:

  • Keep it bookmarkable. Don’t load everything to one page, let users return to a certain section of your app via their bookmarks.
  • Don’t overuse AJAX. Often simple Javascript without server interaction will do. Try to reduce the server callbacks.
  • Minimize the code to be loaded. When you don’t have any other choice, consider code downloading.
  • Speed up your apps with AJAX. Use AJAX for what it was meant for: tune your existing application at points where postbacks need to reload the same page with only little change.

ajax, kiko, bookmark, code downloading, speed