Performance: Returning HTML templates
MEDIUM IMPACT
This affects the page load speed by determining how quickly the server can send the rendered HTML to the browser and how fast the browser can display the content.
def view(request): data = get_lightweight_data() return render(request, 'template.html', {'data': data})
def view(request): data = get_heavy_data() html = render_to_string('template.html', {'data': data}) return HttpResponse(html)
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy synchronous template rendering | N/A (server-side) | N/A | Delays initial paint | [X] Bad |
| Lightweight context with Django render shortcut | N/A (server-side) | N/A | Faster initial paint | [OK] Good |