JavaScript optimisation

First step is to put your JavaScript into its own file rather than on the page itself. By doing this the browser caches the JavaScript and won’t download it on every request. The second step is to use an optimiser to do things like:
  • Remove comments
  • Remove white space
  • Shorten variable names
Some online optimisers are:



For example look at the following VE code:

         var map = null;
         
         function GetMap()
         {
            map = new VEMap('myMap');
            map.LoadMap(new VELatLong(47.6, -122.33), 10 ,'h' ,false);
         }   
versus:
var map=null;function GetMap(){map=new VEMap('myMap');
map.LoadMap(new VELatLong(47.6,-122.33),10,'h',false);}


Size before optimization: 188 bytes
Size after optimization: 110 bytes
Size reduction: 41.5%

Something wrong with the code? Correct it at the Virtual Earth WIKI

JavaScript optimisation