Javascript string concatenation performance on modern browsers: array.join("") is now slower!

Well… as many Javascript developers know, a common practice to handle big string concatenation, is to implement a sort of  “stringBuffer” by using an array as data container and then convert it to a string by using the method join(). Ie:

var buffer = [];
var target = document.getElementById("box");

for (var i=0; i<10000; i++) {
    buffer .push(['<p id="node_', i, '" id="node_', i, '">Content ', i, '</p>'].join(""));
}

target.innerHTML = buffer.join("");

This is theoretically the fastest way to manage huge strings and to speed up the building of dynamic content.

Continue reading

Playing with Google maps API – part three: Geocoding and custom overlay

The main feature provided by the Google maps API, is the ability to convert an human readable location, such “Milan, Italy” to a geographic location represented by latitude and longitude, this process is called geocoding. The GClientGeocoder is the class which provide this service, through the method getLatLng() which accepts two arguments: a string representing an address and a callback function that will be called once the coordinates are retrieved. If the address will be successful located, the callback function will be invoked by passing a GLatLng object as argument, otherwise the function will receive a null. GLatLng is an object which represents a geographic location (latitude and longitude).

To request a geolocation for a given address we use a similar code:

Continue reading