Performance: GZip, Cache-Control, WebP, SQLite-Tuning, Indizes, srcset — SW by-v438, APP_VER 417
This commit is contained in:
parent
5bd07d9598
commit
e0c2b2bdc1
10 changed files with 46 additions and 12 deletions
|
|
@ -10,6 +10,7 @@ from fastapi import FastAPI, Request
|
|||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from fastapi.middleware.gzip import GZipMiddleware
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from database import init_db
|
||||
|
|
@ -98,6 +99,20 @@ class _CacheControlMiddleware(BaseHTTPMiddleware):
|
|||
app.add_middleware(_CacheControlMiddleware)
|
||||
|
||||
|
||||
class MediaCacheMiddleware(BaseHTTPMiddleware):
|
||||
"""Setzt aggressive Cache-Header für /media/-Requests.
|
||||
UUID-basierte Dateinamen ändern sich nie → immutable caching.
|
||||
"""
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
if request.url.path.startswith('/media/'):
|
||||
response.headers['Cache-Control'] = 'public, max-age=31536000, immutable'
|
||||
return response
|
||||
|
||||
app.add_middleware(MediaCacheMiddleware)
|
||||
app.add_middleware(GZipMiddleware, minimum_size=1000)
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# API-Router registrieren (werden nach und nach hinzugefügt)
|
||||
# ------------------------------------------------------------------
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue