How to Asynchronously Load Backbone View Templates

During the development of our third party widgets we decided to use a templating library like Backbone recommends. A templating library would allow the HTML code to be separated from the JavaScript, maximising re-use and avoiding code cluttered with ugly HTML. Ultimately all the templates would be bundled together and packaged into the compressed, single file version of the widgets. However, we still wanted the templates to be retrievable remotely, as and when they were needed. The templating library used below is the one provided by Lo-Dash but it could just as easily be any other library. So here goes, this is how you would asynchronously load backbone view templates.