<story><title>Backbone patterns</title><url>http://ricostacruz.com/backbone-patterns</url><text></text></story><parent_chain></parent_chain><comment><author>conesus</author><text>One of the patterns looks like it requires more processing power than necessary. The rendering of a template should be fast, since you will likely be doing it many times on a page.&lt;p&gt;&lt;pre&gt;&lt;code&gt;    ContactView = Backbone.View.extend({
      template: function() {
        var template = _.template($(&quot;#template-contact&quot;).html());
        return template.apply(this, arguments);
      },

      render: function() {
        // This is a dictionary object of the attributes of the models.
        // =&amp;#62; { name: &quot;Jason&quot;, email: &quot;j.smith@gmail.com&quot; }
        var dict = this.model.toJSON();

        // Pass this object onto the template function.
        // This returns an HTML string.
        var html = this.template(dict);

        // Append the result to the view&apos;s element.
        $(this.el).append(html);

        // ...
      }
    })
&lt;/code&gt;&lt;/pre&gt;
Note that the template is already on the page and has to be serialized by jQuery with the `_.template($(&quot;#template-contact&quot;).html());` line. It would be faster to already have the template in a JavaScript string, ready to be interpolated with your values.&lt;p&gt;Otherwise, for every view you will be fetching the template from the DOM. The difference in implementation would be from this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  &amp;#60;div id=&quot;template-contact&quot;&amp;#62;Mail me at &amp;#60;%= email %&amp;#62;&amp;#60;/div&amp;#62;
&lt;/code&gt;&lt;/pre&gt;
to this:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  &amp;#60;script&amp;#62;var templateContact = &quot;Mail me at &amp;#60;%= email %&amp;#62;&quot;&amp;#60;/script&amp;#62;
&lt;/code&gt;&lt;/pre&gt;
It&apos;s a bit more work, but it reduces the amount of work that has to happen just to render one of many templates.</text></comment>
<story><title>Backbone patterns</title><url>http://ricostacruz.com/backbone-patterns</url><text></text></story><parent_chain></parent_chain><comment><author>jugglinmike</author><text>It&apos;s great to see knowledge like this compiled into one place. Unfortunately, it looks like the resource is only superficially open source.&lt;p&gt;I was about to make a pull request to fix a typo, when I found someone had already done so:
&lt;a href=&quot;https://github.com/rstacruz/backbone-patterns/pull/3&quot; rel=&quot;nofollow&quot;&gt;https://github.com/rstacruz/backbone-patterns/pull/3&lt;/a&gt;&lt;p&gt;If a objective correction like this takes 6 weeks (and counting!) to be merged, does the open nature of this page really matter?&lt;p&gt;Not that this detracts from the message, but take the claim &quot;This is a massive work-in-progress.&quot; with a grain of salt.</text></comment>