Performance: How cookies work in HTTP
MEDIUM IMPACT
Cookies affect page load speed by adding data to HTTP headers, impacting network transfer size and latency.
from flask import Flask, make_response app = Flask(__name__) @app.route('/') def index(): resp = make_response('Hello World') resp.set_cookie('session', 'short_token') return resp
from flask import Flask, make_response app = Flask(__name__) @app.route('/') def index(): resp = make_response('Hello World') resp.set_cookie('session', 'very_long_session_data_string_that_is_unnecessarily_large') return resp
| Pattern | Header Size | Network Latency | Rendering Delay | Verdict |
|---|---|---|---|---|
| Large cookies with long session data | Increases by 1-2 KB | Increases latency by 10-50ms | Delays first paint | [X] Bad |
| Small cookies with minimal data | Minimal increase | Minimal latency impact | Faster first paint | [OK] Good |