Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Client_Side_Rendering_Is_Not_So_Easy.pdf

 Client_Side_Rendering_Is_Not_So_Easy.pdf

nuria_ruiz

July 08, 2012
Tweet

More Decks by nuria_ruiz

Other Decks in Technology

Transcript

  1. To move rendering to the client you need two things:

    1. Template Engine 2. Templates Loads of Javascript in the client.
  2. Back to loads of Javascript in the client... Remember that

    loading bar? 500 K compressed, 23 requests ~ 3300 K of Javascript !!!!
  3. We needed to do ajax to retrieve templates, which are

    HTML docs (cannot use <script>). AND Loads of walking the DOM to insert data.
  4. Faster on IE7 than Chrome. We tried a "new" templating

    technology to solve the DOM issue.
  5. XSLT was faster but had many problems. Browser Implementation is

    1.0. It does not support dynamic subtemplating. Adding translations was a major pain.
  6. With as much Javascript we had in the client nothing

    is going to go fast. Fact #1 We need to load Javascript lazily.
  7. <div class="entry"> <h1>{{title}}</h1> <div class="body"> {{{body}}} </div> </div> Template: Compilation:

    $ npm install handlebars $ /usr/bin/handlebars sample_template.js Builds a grammar based on HTML that compiles to Javascript.
  8. (function() { var template = Handlebars. template['sample_template.js'] =function (Handlebars,depth0,helpers,partials,data) {

    helpers = helpers || Handlebars.helpers; var self = this; buffer += "<div class=\"entry\">\n <h1>"; ..... } buffer += escapeExpression(stack1) + "</h1>\n <div class=\"body\">\n ” .... buffer += escapeExpression(stack1) + "\n </div>\n </div>\n"; return buffer; }); })()
  9. How do we download templates? With YUI, just like anything

    else, templates now are Javascript. <a href="#m=Albums&f=index" onclick=​"Bootloader('t-photo','Request.click', '?m=Albums&f=index)​;​ return false;​" title=​"My photo albums">​…​</a>​
  10. Do we use Client Side Rendering for everything? No. 1.

    Features that exist only client side, like overlays, autocomplete, spinners, chat UI. 2. Features for which there are significant CPU savings to be done, e.g. high traffic pages like photos.