Look at performance optimisation of Javascript string manipulation. See also: - https://hacks.mozilla.org/2012/12/performance-with-javascript-string-objects/ - http://shop.oreilly.com/product/9780596802806.do