Tuesday, August 29, 2006

IE + JavaScript Performance Recommendations

Pre-ajax days javascript was used mostly for form validations, image swaps or little dom manipulations here and there. Back then optimizing the code was of least importance because it never used to do anything significant (if I may put it that way).

Well, now things are very different. With ajax, we have javascript with a complete new look and lots & lots of code written in it. Anyone who has built an application using javascript would realize that sooner or later you are going to run into a situation where your code might start performing miserably. As long as 5-6 items were there, it ran fine but the moment we had to alter 100 rows, our application almost starts to die.

Here is where some good coding practices come into play.

I don't want to repeat what is covered in the article below, so take a look (the article is written with IE in mind, but it very well applies to FF too or basically better coding practices).

IE + JavaScript Performance Recommendations - Part I

  • Declare var for variables that are meant to have local scope
  • Cache Variables Whenever Possible
  • Cache Function Pointers at all costs
  • Avoid Using the ‘with’ Keyword