Performance: JSON responses with jsonify
MEDIUM IMPACT
This affects the speed of sending JSON data from the server to the browser and how quickly the browser can start rendering or processing the response.
from flask import Flask, jsonify app = Flask(__name__) @app.route('/data') def data(): data_dict = {'name': 'Alice', 'age': 30} return jsonify(data_dict)
from flask import Flask, Response import json app = Flask(__name__) @app.route('/data') def data(): data_dict = {'name': 'Alice', 'age': 30} json_str = json.dumps(data_dict) return Response(json_str, mimetype='application/json')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual json.dumps + Response | 0 (server-side only) | 0 | 0 | [!] OK but slower server response |
| Flask jsonify | 0 (server-side only) | 0 | 0 | [OK] Fast, optimized server response |