From eeb923ee1e187fe134e4e29bd9f48d2cf909237b Mon Sep 17 00:00:00 2001 From: Dan LaManna Date: Mon, 30 Nov 2026 11:24:27 -0500 Subject: [PATCH] Compress responses with GZipMiddleware The leaderboard markup repeats the details row template for every submission, so even without the inline scores the milk10k page is 2MB. It is highly repetitive and gzips to about 50KB. --- stade/settings.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stade/settings.py b/stade/settings.py index d0d3ba2..9e9f3cb 100644 --- a/stade/settings.py +++ b/stade/settings.py @@ -41,6 +41,22 @@ def mutate_configuration(configuration: ComposedConfiguration) -> None: configuration.AUTHENTICATION_BACKENDS.insert(0, 'rules.permissions.ObjectPermissionBackend') + # The leaderboard pages are large and highly repetitive, so compression shrinks them by + # an order of magnitude. Following cookiecutter-resonant, GZipMiddleware goes directly + # after WhiteNoiseMiddleware (WhiteNoise compresses static files itself), and the Debug + # Toolbar must come after any middleware that encodes the response's content. + gzip_middleware = 'django.middleware.gzip.GZipMiddleware' + configuration.MIDDLEWARE.insert( + configuration.MIDDLEWARE.index('whitenoise.middleware.WhiteNoiseMiddleware') + 1, + gzip_middleware, + ) + debug_toolbar_middleware = 'debug_toolbar.middleware.DebugToolbarMiddleware' + if debug_toolbar_middleware in configuration.MIDDLEWARE: + configuration.MIDDLEWARE.remove(debug_toolbar_middleware) + configuration.MIDDLEWARE.insert( + configuration.MIDDLEWARE.index(gzip_middleware) + 1, debug_toolbar_middleware + ) + JAZZMIN_SETTINGS = {'related_modal_active': True} SHELL_PLUS_IMPORTS = ['from stade.core.tasks import *']