Performance: Block definitions and overriding
MEDIUM IMPACT
This affects page load speed and rendering by controlling how templates are composed and reused, impacting HTML size and browser rendering.
{% block content %}
<div>
<p>Base content</p>
{% block extra_content %}{% endblock %}
</div>
{% endblock %}
<!-- Child templates override only 'extra_content' block to add custom parts -->{% block content %}
<div>
<p>Static content repeated in many templates</p>
</div>
{% endblock %}
<!-- Overriding blocks by copying entire block content in child templates -->| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Copy entire block content in child templates | More DOM nodes due to duplicated HTML | Multiple reflows from larger DOM | Higher paint cost from complex layout | [X] Bad |
| Override small nested blocks only | Fewer DOM nodes, minimal duplication | Single reflow from smaller DOM | Lower paint cost from simpler layout | [OK] Good |