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 a minifier to do things like:
- Remove comments
- Remove white space
- Shorten variable names
Some online minifiers 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 minification: 188 bytes
Size after minification: 110 bytes
Size reduction: 41.5%