fix: browser gets stuck in a reload loop after a server upgrade (#31631)

After a server upgrade, browsers could keep reusing their cached copy of the old app page for days, since it was sent with no caching instructions. That old page points at files the new version no longer has, so the app reloads into the same cached page and loops until a hard refresh. The app page now tells the browser to check for a newer version on every visit, which is a tiny request when nothing changed. Other files are cached as before, and an admin-set CACHE_CONTROL still takes precedence.

Fixes #31630
This commit is contained in:
Classic298 2026-10-10 19:15:39 +02:00 • committed by GitHub
parent 82f142d376
commit c94ac152ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -319,6 +319,15 @@ class SPAStaticFiles(StaticFiles):
else:
raise ex
def file_response(
self, full_path: str, stat_result: os.stat_result, scope: dict, status_code: int = 200
) -> Response:
response = super().file_response(full_path, stat_result, scope, status_code)
if full_path.endswith('.html'):
# Stale cached HTML references chunks from an older build
response.headers['Cache-Control'] = 'no-cache'
return response
class CORSStaticFiles(StaticFiles):
async def get_response(self, path: str, scope):