Jonathan Bennett

Evolving your views: Enable caching

One of the first big wins we can achieve by separating out view into different objects and partials is better performance through caching. In fact, by deeply nesting our partials, we can easily do Russian Doll Caching.

To take advantage of this, we pull out a post_row.html.erb partial and enabled caching:

<!-- app/views/posts/post_row.html.erb -->
<li><%= link_to post.title, post %></li>

<!-- app/views/posts/post_list.html.erb -->
<ul>
	<%= render partial: "posts/post_row", 
			collection: dashboard.posts, 
			as: :post, 
			cached: true %>
</ul>

This change alone will significantly decrease the render time of your screens.