diff --git a/eosweb/core/main.py b/eosweb/core/main.py index 3e0b1c1..7b26f61 100644 --- a/eosweb/core/main.py +++ b/eosweb/core/main.py @@ -34,7 +34,7 @@ import importlib import json import os -app = flask.Flask(__name__) +app = flask.Flask(__name__, static_folder=None) # Load config app.config.from_object('eosweb.core.settings') @@ -72,6 +72,16 @@ class EosObjectJSONDecoder(flask.json.JSONDecoder): app.json_encoder = EosObjectJSONEncoder app.json_decoder = EosObjectJSONDecoder +# Patch Flask's static file sending to add no-cache +# Allow "caching", but require revalidation via 304 Not Modified +@app.route('/static/') +def static(filename): + cache_timeout = app.get_send_file_max_age(filename) + val = flask.send_from_directory('static', filename, cache_timeout=cache_timeout) + val.headers['Cache-Control'] = val.headers['Cache-Control'].replace('public', 'no-cache') + #import pdb; pdb.set_trace() + return val + @app.cli.command('test') @click.option('--prefix', default=None) @click.option('--lang', default=None) diff --git a/eosweb/core/templates/election/booth.html b/eosweb/core/templates/election/booth.html index d729060..4018dad 100644 --- a/eosweb/core/templates/election/booth.html +++ b/eosweb/core/templates/election/booth.html @@ -98,8 +98,7 @@ (function(templateUrl) { $.ajax({ url: "{{ url_for('static', filename='nunjucks') }}/" + templateUrl, - dataType: "text", - cache: {% if eosweb.app.debug %}false{% else %}true{% endif %} + dataType: "text" }) .done(function(data) { try {