From 12125d0f2d60e03964ba38736660a78f9ff3f895 Mon Sep 17 00:00:00 2001 From: team3 Date: Wed, 24 Jun 2026 07:19:01 +0200 Subject: [PATCH] update --- backend/main.py | 18 +++++++++- frontend/src/components/TopicDetail.vue | 45 +++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/backend/main.py b/backend/main.py index d6be158..c3e2ff8 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,6 +2,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI from fastapi.staticfiles import StaticFiles +from starlette.middleware.gzip import GZipMiddleware from logsetup import setup_logging @@ -22,9 +23,24 @@ async def lifespan(app: FastAPI): await close_db() +class CachedStatic(StaticFiles): + """StaticFiles mit Cache-Control: gehashte Assets dauerhaft (immutable), + index.html nie cachen (verweist immer auf die aktuellen Asset-Hashes).""" + async def get_response(self, path, scope): + resp = await super().get_response(path, scope) + if path.startswith("assets/"): + resp.headers["Cache-Control"] = "public, max-age=31536000, immutable" + else: + resp.headers["Cache-Control"] = "no-cache" + return resp + + app = FastAPI(title="Creator", lifespan=lifespan) +# gzip für JS/CSS-Bundle + große JSON-Antworten (~1,39 MB JS → ~400 KB). +app.add_middleware(GZipMiddleware, minimum_size=500) + app.include_router(router) if FRONTEND_DIST.exists(): - app.mount("/", StaticFiles(directory=FRONTEND_DIST, html=True), name="frontend") + app.mount("/", CachedStatic(directory=FRONTEND_DIST, html=True), name="frontend") diff --git a/frontend/src/components/TopicDetail.vue b/frontend/src/components/TopicDetail.vue index 84f0543..893113e 100644 --- a/frontend/src/components/TopicDetail.vue +++ b/frontend/src/components/TopicDetail.vue @@ -1,5 +1,5 @@