diff --git a/main.py b/main.py index 0846156d..78ccdeff 100644 --- a/main.py +++ b/main.py @@ -3316,4 +3316,18 @@ async def proxy_inventory_service(path: str, request: Request): # Icons are now served from static/icons directory # Serve SPA files (catch-all for frontend routes) # Mount the single-page application frontend (static assets) at root path -app.mount("/", StaticFiles(directory="static", html=True), name="static") +# +# Force browsers to always revalidate static assets so bind-mounted file +# changes are picked up without a hard refresh. The ETag/Last-Modified +# headers already make revalidation efficient (304 responses). +class NoCacheStaticFiles(StaticFiles): + async def get_response(self, path, scope): + response = await super().get_response(path, scope) + # Force revalidation for HTML/JS/CSS/JSON so code changes show up + # immediately after git pull. Other assets (images, fonts) can cache. + if any(path.endswith(ext) for ext in (".html", ".js", ".css", ".json")): + response.headers["Cache-Control"] = "no-cache, must-revalidate" + return response + + +app.mount("/", NoCacheStaticFiles(directory="static", html=True), name="static")