Performance: CORS configuration with Flask-CORS
MEDIUM IMPACT
This affects how browsers handle cross-origin requests, impacting page load speed and interaction responsiveness when fetching resources from different domains.
from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app, resources={r"/data": {"origins": ["https://example.com"]}}) @app.route('/data') def data(): return {'key': 'value'}
from flask import Flask from flask_cors import CORS app = Flask(__name__) CORS(app, resources={r"/*": {"origins": "*"}}) @app.route('/data') def data(): return {'key': 'value'}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Allow all origins with '*' | No direct DOM impact | No reflows | No paint cost | [!] OK but causes network delays |
| Restrict origins to specific domains | No direct DOM impact | No reflows | No paint cost | [OK] Best for network performance |