Performance: Static files in templates
MEDIUM IMPACT
This affects page load speed by controlling how CSS, JavaScript, and images are loaded and cached in the browser.
{% load static %}
<link rel="stylesheet" href="{% static 'css/style.css' %}">
<script src="{% static 'js/script.js' %}"></script>{% load static %}
<link rel="stylesheet" href="/static/css/style.css">
<script src="/static/js/script.js"></script>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Hardcoded static paths | No extra DOM nodes | No reflows from static files | Higher paint cost due to cache misses and blocking | [X] Bad |
| Using {% static %} tag | No extra DOM nodes | No reflows from static files | Lower paint cost due to cache busting and optimized loading | [OK] Good |
| Large images without optimization | No extra DOM nodes | Triggers reflows due to layout shifts | High paint cost and CLS issues | [X] Bad |
| Optimized images with lazy loading | No extra DOM nodes | Minimal reflows, stable layout | Lower paint cost and improved CLS | [OK] Good |