zcbot/web/static_files.py

19 lines
635 B
Python

"""Static file helpers for the Web SPA."""
from __future__ import annotations
from starlette.responses import Response
from fastapi.staticfiles import StaticFiles
class NoCacheStaticFiles(StaticFiles):
"""StaticFiles variant that asks browsers to revalidate SPA assets.
The Web UI is a module graph of small JS files. Without revalidation, users
can keep an old chat.js after a deploy and miss frontend-only fixes.
"""
def file_response(self, *args, **kwargs) -> Response:
response = super().file_response(*args, **kwargs)
response.headers["Cache-Control"] = "no-cache"
return response