Performance: Fragment caching
HIGH IMPACT
Fragment caching improves page load speed by storing parts of the page output to avoid repeated rendering.
<% cache('comments_fragment') do %> <%= render 'comments' %> <% end %>
<%= render 'comments' %> repeated multiple times without caching| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No caching, repeated partial renders | High (many nodes rendered repeatedly) | Multiple reflows per partial | High paint cost due to delayed content | [X] Bad |
| Fragment caching with stored HTML | Low (cached HTML reused) | Single reflow on initial load | Low paint cost, faster content display | [OK] Good |