using Jquery promise to solve race condition generated after rendering handlebars template