Performance: HTML forms with POST method
MEDIUM IMPACT
This affects how quickly form data is sent to the server and how the browser handles page reloads after submission.
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/submit', methods=['POST']) def submit(): data = request.form # process data return jsonify(success=True) <!-- HTML --> <form id="myForm"> <input name="username" /> <button type="submit">Send</button> </form> <script> document.getElementById('myForm').addEventListener('submit', async e => { e.preventDefault(); const formData = new FormData(e.target); await fetch('/submit', { method: 'POST', body: formData }); // update UI without reload }); </script>
<form method="POST" action="/submit"> <input name="username" /> <button type="submit">Send</button> </form>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Standard HTML form POST submit | Single form node | Triggers full page reflow on reload | High paint cost due to full reload | [X] Bad |
| AJAX POST submission with fetch | Single form node | No reflow triggered by submit | Low paint cost, only updates needed parts | [OK] Good |