Performance: File responses
MEDIUM IMPACT
This affects how quickly files are sent from the server to the user, impacting page load speed and user wait time.
from fastapi import FastAPI from fastapi.responses import FileResponse app = FastAPI() @app.get('/download') async def download_file(): return FileResponse('largefile.zip', media_type='application/zip', filename='largefile.zip')
from fastapi import FastAPI from fastapi.responses import Response app = FastAPI() @app.get('/download') async def download_file(): with open('largefile.zip', 'rb') as f: data = f.read() return Response(content=data, media_type='application/zip')
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Reading full file into memory and returning Response | 0 (no DOM) | 0 | 0 | [X] Bad |
| Using FileResponse to stream file | 0 (no DOM) | 0 | 0 | [OK] Good |