5. Why JavaScript Templates ? JavaScript templates are rendered and cached client-side without sending an HTTP request to the server — in other words, they’re lightning fast. Speed benefits aside, JavaScript templates also afford us the opportunity to abstract the administrative UI into a simple JavaScript API. Rich and Faster User Experience Decrease the load on Server [ increase scalability ] Easy to Manage And.. Because the modern web browsers are very powerful
8. HOW DO JAVASCRIPT TEMPLATES LOOK LIKE HTML JSON <div class="entry"> <h1> {{title}} </h1> {{#with author}} <h2>By {{firstName}} {{lastName}} </h2> {{/with}} </div> { title: "My first post!", author: { firstName: "Charles", lastName: "Jolley" } }
9. HOW DO JAVASCRIPT TEMPLATES LOOK LIKE - 2 <script id="movieTemplate" type="text/x-jquery-tmpl"> <tr> <td> {{=Title}} </td> <td> {{#if Languages}} Alternative languages: <em> {{=Languages}} </em>. {{else Subtitles}} Original language only... <br/>Subtitles in <em> {{=Subtitles}} </em>. {{else}} Original version only, without subtitles. {{/if}} </td> </tr> </script>
10. HOW DO JAVASCRIPT TEMPLATES LOOK LIKE - 3 < script type = "text/javascript" > var movies = [{ Title : "Meet Joe Black" , Languages : "English and French" , Subtitles : "English" }, { Title : "Eyes Wide Shut" , Subtitles : "French and Spanish" }, { Title : "The Mighty" }, { Title : "City Hunter" , Languages : "Mandarin and Chinese" }]; $ ( "#movieList" ). html ( $ ( "#movieTemplate" ). render ( movies )); </ script >
15. Same Template for Server side and Client Side Ex. Mustache, Handlebar JS Available in Ruby, JavaScript, Python, Erlang, PHP, Perl, Objective-C, Java, .NET, Android, C++, Go, Lua, ooc, ActionScript, ColdFusion, Scala, Clojure, Fantom, CoffeeScript, D, and for node.js .
16. Same Template for Server side and Client Side (Contd.)
17. JS Templating Good when Loading all data from the server especially in rich list displays Adding or updating new items in lists Anywhere you need to add new complex content to the page Anything that requires client side HTML rendering
18. JavaScript Templating best suited for Stock Related apps Web Admin Panel Live Score Web Desktops Any AJAX Intensive app