Javascript Optimization Techniques

Often we write JavaScript code to perform client side validation or to give fancy dynamic rich interface by using DHTML and Ajax. But have we ever thought of writing a JavaScript code which will not only function as per your requirement but also gives you maximum performance output. To achieve this you need to Optimize your JavaScript code.

Compressing JavaScript Source Code
Whitespace also increases the file size. So if your JavaScript code is pretty huge and has lot of whitespace you will end up in creating a big js file size wise and this will affect the js download time on the client computer. Removing all the unnecessary whitespace will reduce the file size and will reduce the download time.

Remove unwanted declared variable
Every browser allocates some amount of memory for JavaScript Engine for its code execution. If your JavaScript variable stack limit exceeds your program data operation needs then the JavaScript engine will start throwing error related to stack overflow. So it is advisable to remove the instance of variable from the memory when not required.

Your email:

 


Remove variable from memory in JavaScript

  variablename = null;

Your email:

 


Reverse Loop Count:
Increment Operator takes more time to execute than the Decrement Operation. So in a loop operation, Loops starting from 0 to max limit will take more time to execute than the Loops starting from max limit to 0 as the decrement operation takes less time to execute.

Example:

for(i=0;i<1000;i++) { ... }

The above for loop will take more time than

for(i=999;i>=0;i--) { ... }

Custom Search


Popular Articles:

Categories: Javascript Tags:
  1. November 19th, 2007 at 13:10 | #1

    You are often amazed that things you never thought about thinking they are trivial, can make nice difference to what you do. Your small little write up did the same to me today.

    Thanks

  1. No trackbacks yet.