Performance: Form fields and widgets
MEDIUM IMPACT
This affects page load speed and interaction responsiveness by controlling how form elements are rendered and how much HTML and JavaScript is sent to the browser.
from django import forms class MyForm(forms.Form): name = forms.CharField() # uses default TextInput widget
from django import forms class MyForm(forms.Form): name = forms.CharField(widget=forms.TextInput(attrs={'class': 'custom-widget', 'oninput': 'heavyJSFunction()'}))
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Custom widget with heavy JS | High (many nodes and event handlers) | Multiple reflows per input | High paint cost due to styles and scripts | [X] Bad |
| Default widget | Low (simple HTML) | Single reflow on input | Low paint cost | [OK] Good |