Performance: Include for reusable fragments
MEDIUM IMPACT
This affects page load speed by reducing template parsing and rendering time through reuse of common HTML parts.
{% raw %}
<!-- base.html -->
<!DOCTYPE html>
<html>
<head><title>{% block title %}{% endblock %}</title></head>
<body>
{% include 'header.html' %}
{% block content %}{% endblock %}
{% include 'footer.html' %}
</body>
</html>
<!-- page.html -->
{% extends 'base.html' %}
{% block title %}Page{% endblock %}
{% block content %}
<p>Page content here</p>
{% endblock %}
{% endraw %}{% raw %}
<!DOCTYPE html>
<html>
<head>
<title>Page</title>
</head>
<body>
<header>
<h1>Site Title</h1>
<nav>...</nav>
</header>
<!-- page specific content -->
<footer>
<p>Ā© 2024 Company</p>
</footer>
</body>
</html>
{% endraw %}| Pattern | Template Parsing | Server CPU | HTML Size | Verdict |
|---|---|---|---|---|
| Duplicated fragments in every template | High (repeated parsing) | Higher CPU usage | Larger HTML templates | [X] Bad |
| Includes for reusable fragments | Low (parsed once) | Lower CPU usage | Smaller templates | [OK] Good |