Files
pillar/pillar/web/staticfile.py
Sybren A. Stüvel 12272750c3 T53890: Improving static content serving
Static files are now served with an 8-character hash before the last
extension. For example, `tutti.min.js` is now served as
`tutti.min.abcd1234.js`. When doing a request the hash is removed before
serving the static file.

The hash must be 8 characters long, and is taken from STATIC_FILE_HASH.
It is up to the deployment to change this configuration variable
whenever static files change. This forces browsers that download newly
deployed HTML to also refresh the dependencies (most importantly
JS/CSS).

For this to work, the URL must be built with `url_for('static_xxx',
filename='/path/to/file')`. The 'static' module still returns regular,
hashless URLs.
2018-03-23 17:36:14 +01:00

22 lines
565 B
Python

"""Static file handling"""
import logging
import flask
import flask.views
log = logging.getLogger(__name__)
class PillarStaticFile(flask.views.MethodView):
def __init__(self, static_folder):
self.static_folder = static_folder
def get(self, filename):
log.debug('Request file %s/%s', self.static_folder, filename)
return flask.send_from_directory(self.static_folder, filename)
return flask.send_from_directory(
self.static_folder, filename,
conditional=True,
add_etags=True,
)