From d58c04d9745f1a0af46f35fba7b3e2aef704547e Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 29 Nov 2018 10:17:13 +0000 Subject: [PATCH 1/2] Make Whitenoise serve static assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently it’s not configured properly, so isn’t having any effect. This change makes it wrap the Flask app, so it intercepts any requests for static content. Follows the pattern documented in http://whitenoise.evans.io/en/stable/flask.html#enable-whitenoise --- application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.py b/application.py index f4ddca8f7..b8561e2f2 100644 --- a/application.py +++ b/application.py @@ -12,4 +12,4 @@ STATIC_URL = 'static/' app = Flask('app') create_app(app) -application = WhiteNoise(app, STATIC_ROOT, STATIC_URL) +app.wsgi_app = WhiteNoise(app.wsgi_app, STATIC_ROOT, STATIC_URL) From d47e0482d4567208a0651b7a0a634908317aeeb4 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Thu, 29 Nov 2018 12:02:18 +0000 Subject: [PATCH 2/2] Tell browsers not to re-fetch static assets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since we version our asset filenames there’s no need for a browser to ever fetch the same file twice. It should always cache fetch from its own cache. The accepted way to effect this behaviour is using the expires header, which is what this argument to `WhiteNoise` does. --- application.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application.py b/application.py index b8561e2f2..28f9b9cdc 100644 --- a/application.py +++ b/application.py @@ -12,4 +12,4 @@ STATIC_URL = 'static/' app = Flask('app') create_app(app) -app.wsgi_app = WhiteNoise(app.wsgi_app, STATIC_ROOT, STATIC_URL) +app.wsgi_app = WhiteNoise(app.wsgi_app, STATIC_ROOT, STATIC_URL, max_age=WhiteNoise.FOREVER)