Performance: Template inheritance with extends
MEDIUM IMPACT
This affects page load speed by reducing template rendering time and minimizing repeated HTML generation.
<!-- base.html -->
<html>
<head>
<title>{% block title %}My Site{% endblock %}</title>
</head>
<body>
<header>Header content</header>
{% block content %}{% endblock %}
</body>
</html>
<!-- child.html -->
{% extends 'base.html' %}
{% block content %}
Page-specific content
{% endblock %}<!-- base.html content repeated in every template -->
<html>
<head>
<title>My Site</title>
</head>
<body>
<header>Header content</header>
<!-- page-specific content here -->
</body>
</html>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeated full templates | More nodes generated repeatedly | Multiple reflows due to larger DOM | Higher paint cost from larger layout | [X] Bad |
| Template inheritance with extends | Minimal nodes generated per page | Fewer reflows due to smaller DOM | Lower paint cost from focused layout | [OK] Good |