Performance: File download responses
MEDIUM IMPACT
This affects page load speed and user experience by controlling how files are sent from the server to the browser and how quickly the browser can start downloading and rendering the file.
from fastapi import FastAPI from fastapi.responses import StreamingResponse app = FastAPI() @app.get('/download') async def download_file(): def iterfile(): with open('large_file.zip', 'rb') as f: yield from f return StreamingResponse(iterfile(), media_type='application/zip')
from fastapi import FastAPI from fastapi.responses import FileResponse app = FastAPI() @app.get('/download') async def download_file(): return FileResponse('large_file.zip')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| FileResponse for large files | Minimal (no DOM changes) | 0 | 0 | [!] OK but can block server |
| StreamingResponse for large files | Minimal (no DOM changes) | 0 | 0 | [OK] Best for performance |