Flask static file Cache-Control

markdsievers picture markdsievers · Jul 6, 2012 · Viewed 13.3k times · Source

I'm trying to set a reasonable cache expiry for my JS files while in development. I have the standard setup, where HTML, CSS and JS are living under the static directory.

The docs do mention this, but for the life of me I cannot get this to work. I've tried both methods implied, first

class MyFlask(flask.Flask):
    def get_send_file_max_age(self, name):
        if name.lower().endswith('.js'):
            return 60
        return flask.Flask.get_send_file_max_age(self, name)

app = MyFlask(__name__)

and

app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 60

Both have had no effect, my JS files under /static are still coming back with the default cache timeout,

Cache-Control: public, max-age=43200

Any pointers appreciated.

Answer

hllau picture hllau · Apr 17, 2013

You may want to look at webassets to manage the cache expiry. It works in both development and production environment.