diff --git a/app/main/views.py b/app/main/views.py index 7cdb4d60adb5049ed07b9be7947301e972f1fc4b..b98736b0e5e2607fdede36988c7b7977f2771e25 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -9,7 +9,8 @@ This module implements the main blueprint. :license: BSD 2-Clause, see LICENSE for more details. """ -from flask import Blueprint, render_template, jsonify +import os +from flask import Blueprint, render_template, jsonify, request, current_app from flask_login import login_required from .. import utils @@ -34,6 +35,24 @@ def handle_csentry_error(error): return response +@bp.app_url_defaults +def modified_static_file(endpoint, values): + """Add a last modified query parameter to static resource + + Force the browser to invalidate the cache and reload resources + when files have changed + + Inspired from http://flask.pocoo.org/snippets/40/ and + https://gist.github.com/Ostrovski/f16779933ceee3a9d181 + """ + if endpoint == 'static': + filename = values.get('filename') + if filename: + # The same static folder is used for all blueprints + file_path = os.path.join(current_app.static_folder, filename) + values['m'] = int(os.stat(file_path).st_mtime) + + @bp.route('/') @login_required def index():