Biggest AJAX problem

Jul 31
20:22

2006

Remus Stratulat

Remus Stratulat

  • Share this article on Facebook
  • Share this article on Twitter
  • Share this article on Linkedin

Or, how I found myself in front of a 700 MB memory footprint Firefox.

mediaimage

AJAX is becoming the new "de facto" standard in the web application industry. Every where you look on the web there are changes and on almost all sites to approach the AJAX world. Gmail and Yahoo Mail are some of the biggest web applications implementing AJAX and the results on both are amazing.

Browser world

If you ask a JavaScript developer about what is the biggest problem of JavaScript programming it will probably tell you it's browsers' incompatibilities. This is a very big issue and as long as the major players will not come to an understanding (and unfortunately they won't) and provide a common ground it will remain a big issue.

I will not mention here other problems from the CSS world for example.

Fortunately along with AJAX came a lot of frameworks and libraries that address this problem and hide the ugly details from the programmer.

The PROBLEM

In my opinion there is a worse problem then hacking your way around bugs and differences. That problem is represented by memory leaks.

JavaScript VM comes with a garbage collector and aside from some edge cases you might encounter,Biggest AJAX problem Articles it does a pretty good job. Once you close a page a lot of work is done behind the scene to clear unreferenced objects. A lean, mean cleaning machine.

Well... AJAX can mess this up. The page is not closed any more.

The problem is not AJAX in itself as a programming paradigm but in what it can do for the application. With AJAX you can retrieve data from the server without closing the page and rebuilding it. And that data is placed inside the same page and manipulated by JavaScript programs. New DOM objects are created over and over, new JavaScript objects are created based on those data, new events are attached to all this objects. Few programmers destroy those object and unattache the events.

AJAX is still young and most of the people that have done some AJAX implementation for their site are just pulling some HTML parts from the server and using innerHTML to replace the content of a div element. No harm done. As the applications are becoming more and more complex the use case changes. XML or JSON is pulled from the server and DOM objects are created based on them. It is very easy to forget something.

Unfortunately most JavaScript programmers are sloppy. They were taught to be that way by the old browsing habits. There was no need to clean after you. When the page needed some more information, it was regenerated on the server and rendered again by the browser. A clean sheet to work on. Everything that was persistent were the cookies on the browser.

Taking care of your things in JavaScript is harder than you think. Very good programmers missed this. I was using an AJAX application from a well known company (not here to throw the stone) and after heavy usage for about two days without closing my browser, it reached the respected 700 MB footprint in my laptop's memory.

Article "tagged" as:

Categories: