Use no-cache instead of public for Cache-Control

This commit is contained in:
RunasSudo 2017-11-28 13:58:22 +11:00
parent a7b6634281
commit 0f7dfae947
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
2 changed files with 12 additions and 3 deletions

View File

@ -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/<path:filename>')
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)

View File

@ -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 {